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/website_settings/website_settings_bubble_contro
ller.h" | 5 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro
ller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #import <AppKit/AppKit.h> | 9 #import <AppKit/AppKit.h> |
10 | 10 |
11 #include "base/mac/bind_objc_block.h" | 11 #include "base/mac/bind_objc_block.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #import "chrome/browser/certificate_viewer.h" | 14 #import "chrome/browser/certificate_viewer.h" |
15 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
16 #import "chrome/browser/ui/browser_dialogs.h" | 17 #import "chrome/browser/ui/browser_dialogs.h" |
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 21 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
21 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 22 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
22 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 23 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
23 #include "chrome/browser/ui/website_settings/website_settings_utils.h" | 24 #include "chrome/browser/ui/website_settings/website_settings_utils.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/cert_store.h" | 26 #include "content/public/browser/cert_store.h" |
26 #include "content/public/browser/page_navigator.h" | 27 #include "content/public/browser/page_navigator.h" |
| 28 #include "content/public/browser/ssl_host_state_delegate.h" |
27 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
29 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
31 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
32 #include "grit/ui_resources.h" | 34 #include "grit/ui_resources.h" |
33 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 35 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
34 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 36 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
35 #import "ui/base/cocoa/flipped_view.h" | 37 #import "ui/base/cocoa/flipped_view.h" |
36 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); | 510 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); |
509 chrome::ShowCollectedCookiesDialog(webContents_); | 511 chrome::ShowCollectedCookiesDialog(webContents_); |
510 } | 512 } |
511 | 513 |
512 // Handler for the link button to show certificate information. | 514 // Handler for the link button to show certificate information. |
513 - (void)showCertificateInfo:(id)sender { | 515 - (void)showCertificateInfo:(id)sender { |
514 DCHECK(certificateId_); | 516 DCHECK(certificateId_); |
515 ShowCertificateViewerByID(webContents_, [self parentWindow], certificateId_); | 517 ShowCertificateViewerByID(webContents_, [self parentWindow], certificateId_); |
516 } | 518 } |
517 | 519 |
| 520 // Handler for the link button to revoke user certificate decisions. |
| 521 - (void)resetCertificateDecisions:(id)sender { |
| 522 DCHECK(resetDecisionsButton_); |
| 523 ChromeSSLHostStateDelegate* delegate = |
| 524 presenter_->chrome_ssl_host_state_delegate(); |
| 525 DCHECK(delegate); |
| 526 delegate->RevokeUserDecisionsHard(presenter_->site_url().host()); |
| 527 [self close]; |
| 528 } |
| 529 |
518 // Handler for the link to show help information about the connection tab. | 530 // Handler for the link to show help information about the connection tab. |
519 - (void)showHelpPage:(id)sender { | 531 - (void)showHelpPage:(id)sender { |
520 webContents_->OpenURL(content::OpenURLParams( | 532 webContents_->OpenURL(content::OpenURLParams( |
521 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), | 533 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
522 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); | 534 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
523 } | 535 } |
524 | 536 |
525 // Create the contents of the Connection tab and add it to the given tab view. | 537 // Create the contents of the Connection tab and add it to the given tab view. |
526 // Returns a weak reference to the tab view item's view. | 538 // Returns a weak reference to the tab view item's view. |
527 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { | 539 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { |
(...skipping 26 matching lines...) Expand all Loading... |
554 connectionStatusIcon_ = [self addImageWithSize:imageSize | 566 connectionStatusIcon_ = [self addImageWithSize:imageSize |
555 toView:contentView | 567 toView:contentView |
556 atPoint:imagePosition]; | 568 atPoint:imagePosition]; |
557 connectionStatusDescriptionField_ = | 569 connectionStatusDescriptionField_ = |
558 [self addText:base::string16() | 570 [self addText:base::string16() |
559 withSize:[NSFont smallSystemFontSize] | 571 withSize:[NSFont smallSystemFontSize] |
560 bold:NO | 572 bold:NO |
561 toView:contentView.get() | 573 toView:contentView.get() |
562 atPoint:textPosition]; | 574 atPoint:textPosition]; |
563 certificateInfoButton_ = nil; // This will be created only if necessary. | 575 certificateInfoButton_ = nil; // This will be created only if necessary. |
| 576 resetDecisionsButton_ = nil; // This will be created only if necessary. |
564 separatorAfterConnection_ = [self addSeparatorToView:contentView]; | 577 separatorAfterConnection_ = [self addSeparatorToView:contentView]; |
565 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable]; | 578 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable]; |
566 | 579 |
567 firstVisitIcon_ = [self addImageWithSize:imageSize | 580 firstVisitIcon_ = [self addImageWithSize:imageSize |
568 toView:contentView | 581 toView:contentView |
569 atPoint:imagePosition]; | 582 atPoint:imagePosition]; |
570 firstVisitHeaderField_ = | 583 firstVisitHeaderField_ = |
571 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) | 584 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) |
572 withSize:[NSFont smallSystemFontSize] | 585 withSize:[NSFont smallSystemFontSize] |
573 bold:YES | 586 bold:YES |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), | 665 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), |
653 NSMaxY([identityStatusIcon_ frame])); | 666 NSMaxY([identityStatusIcon_ frame])); |
654 if (certificateInfoButton_) { | 667 if (certificateInfoButton_) { |
655 NSRect certificateButtonFrame = [certificateInfoButton_ frame]; | 668 NSRect certificateButtonFrame = [certificateInfoButton_ frame]; |
656 certificateButtonFrame.origin.x = NSMinX( | 669 certificateButtonFrame.origin.x = NSMinX( |
657 [identityStatusDescriptionField_ frame]); | 670 [identityStatusDescriptionField_ frame]); |
658 certificateButtonFrame.origin.y = yPos + kVerticalSpacing; | 671 certificateButtonFrame.origin.y = yPos + kVerticalSpacing; |
659 [certificateInfoButton_ setFrame:certificateButtonFrame]; | 672 [certificateInfoButton_ setFrame:certificateButtonFrame]; |
660 yPos = NSMaxY(certificateButtonFrame); | 673 yPos = NSMaxY(certificateButtonFrame); |
661 } | 674 } |
| 675 if (resetDecisionsButton_) { |
| 676 NSRect resetDecisionsButtonFrame = [resetDecisionsButton_ frame]; |
| 677 resetDecisionsButtonFrame.origin.x = |
| 678 NSMinX([identityStatusDescriptionField_ frame]); |
| 679 resetDecisionsButtonFrame.origin.y = yPos + kVerticalSpacing; |
| 680 [resetDecisionsButton_ setFrame:resetDecisionsButtonFrame]; |
| 681 yPos = NSMaxY(resetDecisionsButtonFrame); |
| 682 } |
662 yPos = [self setYPositionOfView:separatorAfterIdentity_ | 683 yPos = [self setYPositionOfView:separatorAfterIdentity_ |
663 to:yPos + kVerticalSpacing]; | 684 to:yPos + kVerticalSpacing]; |
664 yPos += kVerticalSpacing; | 685 yPos += kVerticalSpacing; |
665 | 686 |
666 // Lay out the connection status section. | 687 // Lay out the connection status section. |
667 [self sizeTextFieldHeightToFit:connectionStatusDescriptionField_]; | 688 [self sizeTextFieldHeightToFit:connectionStatusDescriptionField_]; |
668 [self setYPositionOfView:connectionStatusIcon_ to:yPos]; | 689 [self setYPositionOfView:connectionStatusIcon_ to:yPos]; |
669 [self setYPositionOfView:connectionStatusDescriptionField_ to:yPos]; | 690 [self setYPositionOfView:connectionStatusDescriptionField_ to:yPos]; |
670 yPos = std::max(NSMaxY([connectionStatusDescriptionField_ frame]), | 691 yPos = std::max(NSMaxY([connectionStatusDescriptionField_ frame]), |
671 NSMaxY([connectionStatusIcon_ frame])); | 692 NSMaxY([connectionStatusIcon_ frame])); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 [cell setControlSize:NSSmallControlSize]; | 846 [cell setControlSize:NSSmallControlSize]; |
826 [button setCell:cell.get()]; | 847 [button setCell:cell.get()]; |
827 [button setButtonType:NSMomentaryPushInButton]; | 848 [button setButtonType:NSMomentaryPushInButton]; |
828 [button setBezelStyle:NSRegularSquareBezelStyle]; | 849 [button setBezelStyle:NSRegularSquareBezelStyle]; |
829 [view addSubview:button.get()]; | 850 [view addSubview:button.get()]; |
830 | 851 |
831 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; | 852 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; |
832 return button.get(); | 853 return button.get(); |
833 } | 854 } |
834 | 855 |
| 856 // Add a button with the given text to |view| setting the max size appropriately |
| 857 // for the connection info section. |
| 858 - (NSButton*)addButtonWithTextToConnectionSection:(NSString*)text |
| 859 toView:(NSView*)view { |
| 860 NSRect containerFrame = [view frame]; |
| 861 // Frame size is arbitrary; it will be adjusted by the layout tweaker. |
| 862 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10); |
| 863 base::scoped_nsobject<NSButton> button( |
| 864 [[NSButton alloc] initWithFrame:frame]); |
| 865 |
| 866 // Determine the largest possible size for this button. The size is the width |
| 867 // of the connection section minus the padding on both sides minus the |
| 868 // connection image size and spacing. |
| 869 CGFloat maxTitleWidth = containerFrame.size.width - kFramePadding * 2 - |
| 870 kConnectionImageSize - kConnectionImageSpacing; |
| 871 |
| 872 base::scoped_nsobject<NSButtonCell> cell( |
| 873 [[NSButtonCell alloc] initTextCell:text]); |
| 874 [button setCell:cell.get()]; |
| 875 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; |
| 876 |
| 877 // Ensure the containing view is large enough to contain the button with its |
| 878 // widest possible title. |
| 879 NSRect buttonFrame = [button frame]; |
| 880 buttonFrame.size.width = maxTitleWidth; |
| 881 |
| 882 [button setFrame:buttonFrame]; |
| 883 [button setButtonType:NSMomentaryPushInButton]; |
| 884 [button setBezelStyle:NSRegularSquareBezelStyle]; |
| 885 [view addSubview:button.get()]; |
| 886 |
| 887 return button.get(); |
| 888 } |
| 889 |
835 // Add a pop-up button for |permissionInfo| to the given view. | 890 // Add a pop-up button for |permissionInfo| to the given view. |
836 - (NSPopUpButton*)addPopUpButtonForPermission: | 891 - (NSPopUpButton*)addPopUpButtonForPermission: |
837 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 892 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
838 toView:(NSView*)view | 893 toView:(NSView*)view |
839 atPoint:(NSPoint)point { | 894 atPoint:(NSPoint)point { |
840 | 895 |
841 GURL url = webContents_ ? webContents_->GetURL() : GURL(); | 896 GURL url = webContents_ ? webContents_->GetURL() : GURL(); |
842 __block WebsiteSettingsBubbleController* weakSelf = self; | 897 __block WebsiteSettingsBubbleController* weakSelf = self; |
843 PermissionMenuModel::ChangeCallback callback = | 898 PermissionMenuModel::ChangeCallback callback = |
844 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { | 899 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 certificateId_ = identityInfo.cert_id; | 1045 certificateId_ = identityInfo.cert_id; |
991 if (certificateId_) { | 1046 if (certificateId_) { |
992 if (!certificateInfoButton_) { | 1047 if (!certificateInfoButton_) { |
993 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); | 1048 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); |
994 certificateInfoButton_ = [self addLinkButtonWithText:text | 1049 certificateInfoButton_ = [self addLinkButtonWithText:text |
995 toView:connectionTabContentView_]; | 1050 toView:connectionTabContentView_]; |
996 | 1051 |
997 [certificateInfoButton_ setTarget:self]; | 1052 [certificateInfoButton_ setTarget:self]; |
998 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; | 1053 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; |
999 } | 1054 } |
| 1055 |
| 1056 // Check if a security decision has been made, and if so, add a button to |
| 1057 // allow the user to retract their decision. |
| 1058 if (identityInfo.show_ssl_decision_revoke_button) { |
| 1059 NSString* text = l10n_util::GetNSString( |
| 1060 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON); |
| 1061 resetDecisionsButton_ = |
| 1062 [self addButtonWithTextToConnectionSection:text |
| 1063 toView:connectionTabContentView_]; |
| 1064 [resetDecisionsButton_ setTarget:self]; |
| 1065 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; |
| 1066 } |
1000 } else { | 1067 } else { |
1001 certificateInfoButton_ = nil; | 1068 certificateInfoButton_ = nil; |
1002 } | 1069 } |
1003 | 1070 |
1004 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( | 1071 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( |
1005 identityInfo.identity_status).ToNSImage()]; | 1072 identityInfo.identity_status).ToNSImage()]; |
1006 [identityStatusDescriptionField_ setStringValue: | 1073 [identityStatusDescriptionField_ setStringValue: |
1007 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; | 1074 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; |
1008 | 1075 |
1009 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( | 1076 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 [bubble_controller_ setPermissionInfo:permission_info_list]; | 1224 [bubble_controller_ setPermissionInfo:permission_info_list]; |
1158 } | 1225 } |
1159 | 1226 |
1160 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { | 1227 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { |
1161 [bubble_controller_ setFirstVisit:first_visit]; | 1228 [bubble_controller_ setFirstVisit:first_visit]; |
1162 } | 1229 } |
1163 | 1230 |
1164 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { | 1231 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { |
1165 [bubble_controller_ setSelectedTab:tab_id]; | 1232 [bubble_controller_ setSelectedTab:tab_id]; |
1166 } | 1233 } |
OLD | NEW |