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

Side by Side Diff: chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.mm

Issue 2846913002: Add a Certificate Viewer link to the Page Info dropdown (Closed)
Patch Set: Address nits Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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 26 matching lines...) Expand all
37 #include "skia/ext/skia_utils_mac.h" 37 #include "skia/ext/skia_utils_mac.h"
38 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 38 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
39 #import "ui/base/cocoa/a11y_util.h" 39 #import "ui/base/cocoa/a11y_util.h"
40 #include "ui/base/cocoa/cocoa_base_utils.h" 40 #include "ui/base/cocoa/cocoa_base_utils.h"
41 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 41 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
42 #import "ui/base/cocoa/flipped_view.h" 42 #import "ui/base/cocoa/flipped_view.h"
43 #import "ui/base/cocoa/hover_image_button.h" 43 #import "ui/base/cocoa/hover_image_button.h"
44 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/material_design/material_design_controller.h" 45 #include "ui/base/material_design/material_design_controller.h"
46 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/gfx/image/image_skia_util_mac.h"
47 #import "ui/gfx/mac/coordinate_conversion.h" 48 #import "ui/gfx/mac/coordinate_conversion.h"
48 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 49 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
49 #include "ui/resources/grit/ui_resources.h" 50 #include "ui/resources/grit/ui_resources.h"
50 51
51 using ChosenObjectInfoPtr = std::unique_ptr<PageInfoUI::ChosenObjectInfo>; 52 using ChosenObjectInfoPtr = std::unique_ptr<PageInfoUI::ChosenObjectInfo>;
52 using ChosenObjectDeleteCallback = 53 using ChosenObjectDeleteCallback =
53 base::Callback<void(const PageInfoUI::ChosenObjectInfo&)>; 54 base::Callback<void(const PageInfoUI::ChosenObjectInfo&)>;
54 55
55 namespace { 56 namespace {
56 57
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (location_bar) { 133 if (location_bar) {
133 NSPoint bubble_point = location_bar->GetPageInfoBubblePoint(); 134 NSPoint bubble_point = location_bar->GetPageInfoBubblePoint();
134 origin = ui::ConvertPointFromWindowToScreen(parent, bubble_point); 135 origin = ui::ConvertPointFromWindowToScreen(parent, bubble_point);
135 } 136 }
136 } 137 }
137 return origin; 138 return origin;
138 } 139 }
139 140
140 } // namespace 141 } // namespace
141 142
143 // The |InspectLinkView| objects are used to show the Cookie and Certificate
144 // status and a link to inspect the underlying data.
145 @interface InspectLinkView : FlippedView
146 @end
147
148 @implementation InspectLinkView {
149 NSButton* actionLink_;
150 }
151
152 - (id)initWithFrame:(NSRect)frame {
153 if (self = [super initWithFrame:frame]) {
154 [self setAutoresizingMask:NSViewWidthSizable];
155 }
156 return self;
157 }
158
159 - (void)setActionLink:(NSButton*)actionLink {
160 actionLink_ = actionLink;
161 }
162
163 - (void)setLinkText:(NSString*)linkText {
164 [actionLink_ setTitle:linkText];
165 [GTMUILocalizerAndLayoutTweaker sizeToFitView:actionLink_];
166 }
167
168 - (void)setLinkToolTip:(NSString*)linkToolTip {
169 [actionLink_ setToolTip:linkToolTip];
170 }
171
172 - (void)setLinkTarget:(NSObject*)target withAction:(SEL)action {
173 [actionLink_ setTarget:target];
174 [actionLink_ setAction:action];
175 }
176 @end
177
142 @interface ChosenObjectDeleteButton : HoverImageButton { 178 @interface ChosenObjectDeleteButton : HoverImageButton {
143 @private 179 @private
144 ChosenObjectInfoPtr objectInfo_; 180 ChosenObjectInfoPtr objectInfo_;
145 ChosenObjectDeleteCallback callback_; 181 ChosenObjectDeleteCallback callback_;
146 } 182 }
147 183
148 // Designated initializer. Takes ownership of |objectInfo|. 184 // Designated initializer. Takes ownership of |objectInfo|.
149 - (instancetype)initWithChosenObject:(ChosenObjectInfoPtr)objectInfo 185 - (instancetype)initWithChosenObject:(ChosenObjectInfoPtr)objectInfo
150 atPoint:(NSPoint)point 186 atPoint:(NSPoint)point
151 withCallback:(ChosenObjectDeleteCallback)callback; 187 withCallback:(ChosenObjectDeleteCallback)callback;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 398
363 // Create and return a subview for the site settings and add it to the given 399 // Create and return a subview for the site settings and add it to the given
364 // |superview|. |superview| retains the new view. 400 // |superview|. |superview| retains the new view.
365 - (NSView*)addSiteSettingsSectionToView:(NSView*)superview { 401 - (NSView*)addSiteSettingsSectionToView:(NSView*)superview {
366 base::scoped_nsobject<NSView> siteSettingsSectionView( 402 base::scoped_nsobject<NSView> siteSettingsSectionView(
367 [[FlippedView alloc] initWithFrame:[superview frame]]); 403 [[FlippedView alloc] initWithFrame:[superview frame]]);
368 [superview addSubview:siteSettingsSectionView]; 404 [superview addSubview:siteSettingsSectionView];
369 405
370 // Initialize the two containers that hold the controls. The initial frames 406 // Initialize the two containers that hold the controls. The initial frames
371 // are arbitrary, and will be adjusted after the controls are laid out. 407 // are arbitrary, and will be adjusted after the controls are laid out.
372 cookiesView_ = 408 PageInfoUI::PermissionInfo info;
373 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; 409 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
374 [cookiesView_ setAutoresizingMask:NSViewWidthSizable]; 410 info.setting = CONTENT_SETTING_ALLOW;
375 [siteSettingsSectionView addSubview:cookiesView_]; 411 cookiesView_ = [self
412 addInspectLinkToView:siteSettingsSectionView
413 sectionIcon:PageInfoUI::GetPermissionIcon(info).ToNSImage()
414 sectionTitle:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES)
415 linkText:l10n_util::GetPluralNSStringF(
416 IDS_PAGE_INFO_NUM_COOKIES, 0)];
417 [cookiesView_ setLinkTarget:self
418 withAction:@selector(showCookiesAndSiteData:)];
376 419
377 permissionsView_ = 420 permissionsView_ =
378 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; 421 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease];
379 [siteSettingsSectionView addSubview:permissionsView_]; 422 [siteSettingsSectionView addSubview:permissionsView_];
380 423
424 // The certificate section is created on demand.
425 certificateView_ = nil;
426
381 // Create the link button to view site settings. Its position will be set in 427 // Create the link button to view site settings. Its position will be set in
382 // performLayout. 428 // performLayout.
383 NSString* siteSettingsButtonText = 429 NSString* siteSettingsButtonText =
384 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK); 430 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK);
385 siteSettingsButton_ = [self addButtonWithText:siteSettingsButtonText 431 siteSettingsButton_ = [self addButtonWithText:siteSettingsButtonText
386 toView:siteSettingsSectionView]; 432 toView:siteSettingsSectionView];
387 [GTMUILocalizerAndLayoutTweaker sizeToFitView:siteSettingsButton_]; 433 [GTMUILocalizerAndLayoutTweaker sizeToFitView:siteSettingsButton_];
388 434
389 [siteSettingsButton_ setTarget:self]; 435 [siteSettingsButton_ setTarget:self];
390 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)]; 436 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)];
391 437
392 return siteSettingsSectionView.get(); 438 return siteSettingsSectionView.get();
393 } 439 }
394 440
441 - (InspectLinkView*)addInspectLinkToView:(NSView*)superview
442 sectionIcon:(NSImage*)imageIcon
443 sectionTitle:(const base::string16&)titleText
444 linkText:(NSString*)linkText {
445 // Create the subview.
446 base::scoped_nsobject<InspectLinkView> newView(
447 [[InspectLinkView alloc] initWithFrame:[superview frame]]);
448 [superview addSubview:newView];
449
450 bool isRTL = base::i18n::IsRTL();
451 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
452
453 CGFloat viewWidth = NSWidth([newView frame]);
454
455 // Reset X for the icon.
456 if (isRTL) {
457 controlOrigin.x =
458 viewWidth - kPermissionImageSize - kSectionHorizontalPadding;
459 }
460
461 NSImageView* imageView = [self addImageWithSize:[imageIcon size]
462 toView:newView
463 atPoint:controlOrigin];
464 [imageView setImage:imageIcon];
465
466 NSButton* actionLink = [self addLinkButtonWithText:linkText toView:newView];
467 [newView setActionLink:actionLink];
468
469 if (isRTL) {
470 controlOrigin.x -= kPermissionImageSpacing;
471 NSTextField* sectionTitle = [self addText:titleText
472 withSize:[NSFont systemFontSize]
473 bold:NO
474 toView:newView
475 atPoint:controlOrigin];
476 [sectionTitle sizeToFit];
477
478 NSPoint sectionTitleOrigin = [sectionTitle frame].origin;
479 sectionTitleOrigin.x -= NSWidth([sectionTitle frame]);
480 [sectionTitle setFrameOrigin:sectionTitleOrigin];
481
482 // Align the icon with the text.
483 [self alignPermissionIcon:imageView withTextField:sectionTitle];
484
485 controlOrigin.y +=
486 NSHeight([sectionTitle frame]) + kPermissionLabelBottomPadding;
487 controlOrigin.x -= NSWidth([actionLink frame]) - kLinkButtonXAdjustment;
488 [actionLink setFrameOrigin:controlOrigin];
489 } else {
490 controlOrigin.x += kPermissionImageSize + 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 // Align the icon with the text.
499 [self alignPermissionIcon:imageView withTextField:sectionTitle];
500
501 controlOrigin.y +=
502 NSHeight([sectionTitle frame]) + kPermissionLabelBottomPadding;
503 controlOrigin.x -= kLinkButtonXAdjustment;
504 [actionLink setFrameOrigin:controlOrigin];
505 }
506
507 controlOrigin.y += NSHeight([actionLink frame]);
508 [newView setFrameSize:NSMakeSize(NSWidth([newView frame]), controlOrigin.y)];
509
510 return newView.get();
511 }
512
395 // Handler for the link button below the list of cookies. 513 // Handler for the link button below the list of cookies.
396 - (void)showCookiesAndSiteData:(id)sender { 514 - (void)showCookiesAndSiteData:(id)sender {
397 DCHECK(webContents_); 515 DCHECK(webContents_);
398 DCHECK(presenter_); 516 DCHECK(presenter_);
399 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); 517 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED);
400 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies(); 518 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies();
401 } 519 }
402 520
403 // Handler for the site settings button below the list of permissions. 521 // Handler for the site settings button below the list of permissions.
404 - (void)showSiteSettingsData:(id)sender { 522 - (void)showSiteSettingsData:(id)sender {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 yPos)]; 641 yPos)];
524 yPos = NSMaxY([resetDecisionsButton_ frame]); 642 yPos = NSMaxY([resetDecisionsButton_ frame]);
525 } 643 }
526 644
527 // Resize the height based on contents. 645 // Resize the height based on contents.
528 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding]; 646 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding];
529 } 647 }
530 648
531 - (void)layoutSiteSettingsSection { 649 - (void)layoutSiteSettingsSection {
532 // Start the layout with the first element. Margins are handled by the caller. 650 // Start the layout with the first element. Margins are handled by the caller.
533 CGFloat yPos = 0; 651 CGFloat yPos = kSectionVerticalPadding;
534 652
535 yPos = 653 if (certificateView_) {
536 [self setYPositionOfView:cookiesView_ to:yPos + kSectionVerticalPadding]; 654 yPos = [self setYPositionOfView:certificateView_ to:yPos] +
655 kPermissionsVerticalSpacing;
656 }
657
658 yPos = [self setYPositionOfView:cookiesView_ to:yPos];
537 659
538 if (permissionsPresent_) { 660 if (permissionsPresent_) {
539 // Put the permission info just below the link button. 661 // Put the permission info just below the link button.
540 yPos = [self setYPositionOfView:permissionsView_ to:yPos]; 662 yPos = [self setYPositionOfView:permissionsView_ to:yPos];
541 } 663 }
542 664
543 yPos = [self layoutViewAtRTLStart:siteSettingsButton_ withYPosition:yPos]; 665 yPos = [self layoutViewAtRTLStart:siteSettingsButton_ withYPosition:yPos];
544 666
545 // Resize the height based on contents. 667 // Resize the height based on contents.
546 [self setHeightOfView:siteSettingsSectionView_ 668 [self setHeightOfView:siteSettingsSectionView_
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 buttonFrame.size.width = maxTitleWidth; 801 buttonFrame.size.width = maxTitleWidth;
680 802
681 [button setFrame:buttonFrame]; 803 [button setFrame:buttonFrame];
682 [button setButtonType:NSMomentaryPushInButton]; 804 [button setButtonType:NSMomentaryPushInButton];
683 [button setBezelStyle:NSRegularSquareBezelStyle]; 805 [button setBezelStyle:NSRegularSquareBezelStyle];
684 [view addSubview:button.get()]; 806 [view addSubview:button.get()];
685 807
686 return button.get(); 808 return button.get();
687 } 809 }
688 810
689 // Set the content of the identity and identity status fields. 811 // Set the content of the identity and identity status fields, and add the
812 // Certificate view if applicable.
690 - (void)setIdentityInfo:(const PageInfoUI::IdentityInfo&)identityInfo { 813 - (void)setIdentityInfo:(const PageInfoUI::IdentityInfo&)identityInfo {
691 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = 814 std::unique_ptr<PageInfoUI::SecurityDescription> security_description =
692 identityInfo.GetSecurityDescription(); 815 identityInfo.GetSecurityDescription();
693 [securitySummaryField_ 816 [securitySummaryField_
694 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; 817 setStringValue:SysUTF16ToNSString(security_description->summary)];
695 818
696 [securityDetailsField_ 819 [securityDetailsField_
697 setStringValue:SysUTF16ToNSString(security_description->details)]; 820 setStringValue:SysUTF16ToNSString(security_description->details)];
698 821
699 certificate_ = identityInfo.certificate; 822 certificate_ = identityInfo.certificate;
700 823
701 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { 824 if (certificate_) {
702 resetDecisionsField_ = 825 if (identityInfo.show_ssl_decision_revoke_button) {
703 [self addText:base::string16() 826 resetDecisionsField_ =
704 withSize:[NSFont smallSystemFontSize] 827 [self addText:base::string16()
705 bold:NO 828 withSize:[NSFont smallSystemFontSize]
706 toView:securitySectionView_ 829 bold:NO
707 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)]; 830 toView:securitySectionView_
708 [resetDecisionsField_ 831 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)];
709 setStringValue:l10n_util::GetNSString( 832 [resetDecisionsField_
710 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)]; 833 setStringValue:l10n_util::GetNSString(
711 [self sizeTextFieldHeightToFit:resetDecisionsField_]; 834 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)];
835 [self sizeTextFieldHeightToFit:resetDecisionsField_];
712 836
713 resetDecisionsButton_ = 837 resetDecisionsButton_ =
714 [self addLinkButtonWithText: 838 [self addLinkButtonWithText:
715 l10n_util::GetNSString( 839 l10n_util::GetNSString(
716 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON) 840 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)
717 toView:securitySectionView_]; 841 toView:securitySectionView_];
718 [resetDecisionsButton_ setTarget:self]; 842 [resetDecisionsButton_ setTarget:self];
719 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; 843 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)];
844 }
845
846 if (PageInfoUI::ShouldShowCertificateLink()) {
847 bool isValid = (identityInfo.identity_status !=
848 PageInfo::SITE_IDENTITY_STATUS_ERROR);
849 NSString* linkText = l10n_util::GetNSString(
850 isValid ? IDS_PAGE_INFO_CERTIFICATE_VALID_LINK
851 : IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK);
852
853 certificateView_ =
854 [self addInspectLinkToView:siteSettingsSectionView_
855 sectionIcon:NSImageFromImageSkia(
856 PageInfoUI::GetCertificateIcon())
857 sectionTitle:l10n_util::GetStringUTF16(
858 IDS_PAGE_INFO_CERTIFICATE)
859 linkText:linkText];
860 if (isValid) {
861 [certificateView_
862 setLinkToolTip:l10n_util::GetNSStringF(
863 IDS_PAGE_INFO_CERTIFICATE_VALID_LINK_TOOLTIP,
864 base::UTF8ToUTF16(
865 certificate_->issuer().GetDisplayName()))];
866 }
867
868 [certificateView_ setLinkTarget:self
869 withAction:@selector(showCertificateInfo:)];
870 }
720 } 871 }
721 872
722 [self performLayout]; 873 [self performLayout];
723 } 874 }
724 875
725 // Add a pop-up button for |permissionInfo| to the given view. 876 // Add a pop-up button for |permissionInfo| to the given view.
726 - (NSPopUpButton*)addPopUpButtonForPermission: 877 - (NSPopUpButton*)addPopUpButtonForPermission:
727 (const PageInfoUI::PermissionInfo&)permissionInfo 878 (const PageInfoUI::PermissionInfo&)permissionInfo
728 toView:(NSView*)view 879 toView:(NSView*)view
729 atPoint:(NSPoint)point { 880 atPoint:(NSPoint)point {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 // Align an image with a text field by vertically centering the image on 1157 // Align an image with a text field by vertically centering the image on
1007 // the cap height of the first line of text. 1158 // the cap height of the first line of text.
1008 - (void)alignPermissionIcon:(NSImageView*)imageView 1159 - (void)alignPermissionIcon:(NSImageView*)imageView
1009 withTextField:(NSTextField*)textField { 1160 withTextField:(NSTextField*)textField {
1010 NSRect frame = [imageView frame]; 1161 NSRect frame = [imageView frame];
1011 frame.origin.y += kPermissionIconYAdjustment; 1162 frame.origin.y += kPermissionIconYAdjustment;
1012 [imageView setFrame:frame]; 1163 [imageView setFrame:frame];
1013 } 1164 }
1014 1165
1015 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { 1166 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList {
1016 // A result of re-ordering of the permissions (crbug.com/444244) is
1017 // that sometimes permissions may not be displayed at all, so it's
1018 // incorrect to check they are set before the cookie info.
1019
1020 // |cookieInfoList| should only ever have 2 items: first- and third-party 1167 // |cookieInfoList| should only ever have 2 items: first- and third-party
1021 // cookies. 1168 // cookies.
1022 DCHECK_EQ(cookieInfoList.size(), 2u); 1169 DCHECK_EQ(cookieInfoList.size(), 2u);
1023 1170
1024 int totalAllowed = 0; 1171 int totalAllowed = 0;
1025 for (const auto& i : cookieInfoList) { 1172 for (const auto& i : cookieInfoList) {
1026 totalAllowed += i.allowed; 1173 totalAllowed += i.allowed;
1027 } 1174 }
1028 base::string16 label_text =
1029 l10n_util::GetPluralStringFUTF16(IDS_PAGE_INFO_NUM_COOKIES, totalAllowed);
1030 1175
1031 base::string16 sectionTitle = 1176 [cookiesView_ setLinkText:l10n_util::GetPluralNSStringF(
1032 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA); 1177 IDS_PAGE_INFO_NUM_COOKIES, totalAllowed)];
1033 bool isRTL = base::i18n::IsRTL();
1034
1035 [cookiesView_ setSubviews:[NSArray array]];
1036 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1037
1038 CGFloat viewWidth = NSWidth([cookiesView_ frame]);
1039
1040 // Reset X for the cookie image.
1041 if (isRTL) {
1042 controlOrigin.x = viewWidth - kPermissionImageSize -
1043 kPermissionImageSpacing - kSectionHorizontalPadding;
1044 }
1045
1046 PageInfoUI::PermissionInfo info;
1047 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
1048 info.setting = CONTENT_SETTING_ALLOW;
1049 // info.default_setting, info.source, and info.is_incognito have not been set,
1050 // but GetPermissionIcon doesn't use any of those.
1051 NSImage* image = PageInfoUI::GetPermissionIcon(info).ToNSImage();
1052 NSImageView* imageView = [self addImageWithSize:[image size]
1053 toView:cookiesView_
1054 atPoint:controlOrigin];
1055 [imageView setImage:image];
1056
1057 NSButton* cookiesButton =
1058 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text)
1059 toView:cookiesView_];
1060 [cookiesButton setTarget:self];
1061 [cookiesButton setAction:@selector(showCookiesAndSiteData:)];
1062
1063 if (isRTL) {
1064 controlOrigin.x -= kPermissionImageSpacing;
1065 NSTextField* cookiesLabel =
1066 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES)
1067 withSize:[NSFont systemFontSize]
1068 bold:NO
1069 toView:cookiesView_
1070 atPoint:controlOrigin];
1071 [cookiesLabel sizeToFit];
1072
1073 NSPoint cookiesLabelOrigin = [cookiesLabel frame].origin;
1074 cookiesLabelOrigin.x -= NSWidth([cookiesLabel frame]);
1075 [cookiesLabel setFrameOrigin:cookiesLabelOrigin];
1076
1077 // Align the icon with the text.
1078 [self alignPermissionIcon:imageView withTextField:cookiesLabel];
1079
1080 controlOrigin.y +=
1081 NSHeight([cookiesLabel frame]) + kPermissionLabelBottomPadding;
1082 controlOrigin.x -= NSWidth([cookiesButton frame]) - kLinkButtonXAdjustment;
1083 [cookiesButton setFrameOrigin:controlOrigin];
1084 } else {
1085 controlOrigin.x += kPermissionImageSize + kPermissionImageSpacing;
1086 NSTextField* cookiesLabel =
1087 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES)
1088 withSize:[NSFont systemFontSize]
1089 bold:NO
1090 toView:cookiesView_
1091 atPoint:controlOrigin];
1092 [cookiesLabel sizeToFit];
1093
1094 controlOrigin.y +=
1095 NSHeight([cookiesLabel frame]) + kPermissionLabelBottomPadding;
1096 controlOrigin.x -= kLinkButtonXAdjustment;
1097 [cookiesButton setFrameOrigin:controlOrigin];
1098
1099 // Align the icon with the text.
1100 [self alignPermissionIcon:imageView withTextField:cookiesLabel];
1101 }
1102
1103 controlOrigin.y += NSHeight([cookiesButton frame]);
1104 [cookiesView_
1105 setFrameSize:NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)];
1106
1107 [self performLayout]; 1178 [self performLayout];
1108 } 1179 }
1109 1180
1110 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList 1181 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList
1111 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { 1182 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList {
1112 [permissionsView_ setSubviews:[NSArray array]]; 1183 [permissionsView_ setSubviews:[NSArray array]];
1113 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 1184 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1114 1185
1115 permissionsPresent_ = YES; 1186 permissionsPresent_ = YES;
1116 1187
1117 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { 1188 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) {
1118 base::string16 sectionTitle =
1119 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_PERMISSIONS);
1120
1121 for (const auto& permission : permissionInfoList) { 1189 for (const auto& permission : permissionInfoList) {
1122 controlOrigin.y += kPermissionsVerticalSpacing; 1190 controlOrigin.y += kPermissionsVerticalSpacing;
1123 NSPoint rowBottomRight = [self addPermission:permission 1191 NSPoint rowBottomRight = [self addPermission:permission
1124 toView:permissionsView_ 1192 toView:permissionsView_
1125 atPoint:controlOrigin]; 1193 atPoint:controlOrigin];
1126 controlOrigin.y = rowBottomRight.y; 1194 controlOrigin.y = rowBottomRight.y;
1127 } 1195 }
1128 1196
1129 for (auto& object : chosenObjectInfoList) { 1197 for (auto& object : chosenObjectInfoList) {
1130 controlOrigin.y += kPermissionsVerticalSpacing; 1198 controlOrigin.y += kPermissionsVerticalSpacing;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) { 1287 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) {
1220 [bubble_controller_ setCookieInfo:cookie_info_list]; 1288 [bubble_controller_ setCookieInfo:cookie_info_list];
1221 } 1289 }
1222 1290
1223 void PageInfoUIBridge::SetPermissionInfo( 1291 void PageInfoUIBridge::SetPermissionInfo(
1224 const PermissionInfoList& permission_info_list, 1292 const PermissionInfoList& permission_info_list,
1225 ChosenObjectInfoList chosen_object_info_list) { 1293 ChosenObjectInfoList chosen_object_info_list) {
1226 [bubble_controller_ setPermissionInfo:permission_info_list 1294 [bubble_controller_ setPermissionInfo:permission_info_list
1227 andChosenObjects:std::move(chosen_object_info_list)]; 1295 andChosenObjects:std::move(chosen_object_info_list)];
1228 } 1296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698