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" | |
17 #import "chrome/browser/ui/browser_dialogs.h" | 16 #import "chrome/browser/ui/browser_dialogs.h" |
18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
19 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
21 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
22 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 21 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
23 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 22 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
24 #include "chrome/browser/ui/website_settings/website_settings_utils.h" | 23 #include "chrome/browser/ui/website_settings/website_settings_utils.h" |
25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
26 #include "content/public/browser/cert_store.h" | 25 #include "content/public/browser/cert_store.h" |
27 #include "content/public/browser/page_navigator.h" | 26 #include "content/public/browser/page_navigator.h" |
28 #include "content/public/browser/ssl_host_state_delegate.h" | |
29 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
30 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
31 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
32 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
33 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
34 #include "grit/ui_resources.h" | 32 #include "grit/ui_resources.h" |
35 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 33 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
36 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 34 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
37 #import "ui/base/cocoa/flipped_view.h" | 35 #import "ui/base/cocoa/flipped_view.h" |
38 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); | 508 base::UserMetricsAction("WebsiteSettings_CookiesDialogOpened")); |
511 chrome::ShowCollectedCookiesDialog(webContents_); | 509 chrome::ShowCollectedCookiesDialog(webContents_); |
512 } | 510 } |
513 | 511 |
514 // Handler for the link button to show certificate information. | 512 // Handler for the link button to show certificate information. |
515 - (void)showCertificateInfo:(id)sender { | 513 - (void)showCertificateInfo:(id)sender { |
516 DCHECK(certificateId_); | 514 DCHECK(certificateId_); |
517 ShowCertificateViewerByID(webContents_, [self parentWindow], certificateId_); | 515 ShowCertificateViewerByID(webContents_, [self parentWindow], certificateId_); |
518 } | 516 } |
519 | 517 |
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 | |
530 // Handler for the link to show help information about the connection tab. | 518 // Handler for the link to show help information about the connection tab. |
531 - (void)showHelpPage:(id)sender { | 519 - (void)showHelpPage:(id)sender { |
532 webContents_->OpenURL(content::OpenURLParams( | 520 webContents_->OpenURL(content::OpenURLParams( |
533 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), | 521 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
534 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); | 522 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
535 } | 523 } |
536 | 524 |
537 // Create the contents of the Connection tab and add it to the given tab view. | 525 // Create the contents of the Connection tab and add it to the given tab view. |
538 // Returns a weak reference to the tab view item's view. | 526 // Returns a weak reference to the tab view item's view. |
539 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { | 527 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { |
(...skipping 26 matching lines...) Expand all Loading... |
566 connectionStatusIcon_ = [self addImageWithSize:imageSize | 554 connectionStatusIcon_ = [self addImageWithSize:imageSize |
567 toView:contentView | 555 toView:contentView |
568 atPoint:imagePosition]; | 556 atPoint:imagePosition]; |
569 connectionStatusDescriptionField_ = | 557 connectionStatusDescriptionField_ = |
570 [self addText:base::string16() | 558 [self addText:base::string16() |
571 withSize:[NSFont smallSystemFontSize] | 559 withSize:[NSFont smallSystemFontSize] |
572 bold:NO | 560 bold:NO |
573 toView:contentView.get() | 561 toView:contentView.get() |
574 atPoint:textPosition]; | 562 atPoint:textPosition]; |
575 certificateInfoButton_ = nil; // This will be created only if necessary. | 563 certificateInfoButton_ = nil; // This will be created only if necessary. |
576 resetDecisionsButton_ = nil; // This will be created only if necessary. | |
577 separatorAfterConnection_ = [self addSeparatorToView:contentView]; | 564 separatorAfterConnection_ = [self addSeparatorToView:contentView]; |
578 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable]; | 565 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable]; |
579 | 566 |
580 firstVisitIcon_ = [self addImageWithSize:imageSize | 567 firstVisitIcon_ = [self addImageWithSize:imageSize |
581 toView:contentView | 568 toView:contentView |
582 atPoint:imagePosition]; | 569 atPoint:imagePosition]; |
583 firstVisitHeaderField_ = | 570 firstVisitHeaderField_ = |
584 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) | 571 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) |
585 withSize:[NSFont smallSystemFontSize] | 572 withSize:[NSFont smallSystemFontSize] |
586 bold:YES | 573 bold:YES |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), | 652 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), |
666 NSMaxY([identityStatusIcon_ frame])); | 653 NSMaxY([identityStatusIcon_ frame])); |
667 if (certificateInfoButton_) { | 654 if (certificateInfoButton_) { |
668 NSRect certificateButtonFrame = [certificateInfoButton_ frame]; | 655 NSRect certificateButtonFrame = [certificateInfoButton_ frame]; |
669 certificateButtonFrame.origin.x = NSMinX( | 656 certificateButtonFrame.origin.x = NSMinX( |
670 [identityStatusDescriptionField_ frame]); | 657 [identityStatusDescriptionField_ frame]); |
671 certificateButtonFrame.origin.y = yPos + kVerticalSpacing; | 658 certificateButtonFrame.origin.y = yPos + kVerticalSpacing; |
672 [certificateInfoButton_ setFrame:certificateButtonFrame]; | 659 [certificateInfoButton_ setFrame:certificateButtonFrame]; |
673 yPos = NSMaxY(certificateButtonFrame); | 660 yPos = NSMaxY(certificateButtonFrame); |
674 } | 661 } |
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 } | |
683 yPos = [self setYPositionOfView:separatorAfterIdentity_ | 662 yPos = [self setYPositionOfView:separatorAfterIdentity_ |
684 to:yPos + kVerticalSpacing]; | 663 to:yPos + kVerticalSpacing]; |
685 yPos += kVerticalSpacing; | 664 yPos += kVerticalSpacing; |
686 | 665 |
687 // Lay out the connection status section. | 666 // Lay out the connection status section. |
688 [self sizeTextFieldHeightToFit:connectionStatusDescriptionField_]; | 667 [self sizeTextFieldHeightToFit:connectionStatusDescriptionField_]; |
689 [self setYPositionOfView:connectionStatusIcon_ to:yPos]; | 668 [self setYPositionOfView:connectionStatusIcon_ to:yPos]; |
690 [self setYPositionOfView:connectionStatusDescriptionField_ to:yPos]; | 669 [self setYPositionOfView:connectionStatusDescriptionField_ to:yPos]; |
691 yPos = std::max(NSMaxY([connectionStatusDescriptionField_ frame]), | 670 yPos = std::max(NSMaxY([connectionStatusDescriptionField_ frame]), |
692 NSMaxY([connectionStatusIcon_ frame])); | 671 NSMaxY([connectionStatusIcon_ frame])); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 [cell setControlSize:NSSmallControlSize]; | 825 [cell setControlSize:NSSmallControlSize]; |
847 [button setCell:cell.get()]; | 826 [button setCell:cell.get()]; |
848 [button setButtonType:NSMomentaryPushInButton]; | 827 [button setButtonType:NSMomentaryPushInButton]; |
849 [button setBezelStyle:NSRegularSquareBezelStyle]; | 828 [button setBezelStyle:NSRegularSquareBezelStyle]; |
850 [view addSubview:button.get()]; | 829 [view addSubview:button.get()]; |
851 | 830 |
852 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; | 831 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; |
853 return button.get(); | 832 return button.get(); |
854 } | 833 } |
855 | 834 |
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 | |
890 // Add a pop-up button for |permissionInfo| to the given view. | 835 // Add a pop-up button for |permissionInfo| to the given view. |
891 - (NSPopUpButton*)addPopUpButtonForPermission: | 836 - (NSPopUpButton*)addPopUpButtonForPermission: |
892 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 837 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
893 toView:(NSView*)view | 838 toView:(NSView*)view |
894 atPoint:(NSPoint)point { | 839 atPoint:(NSPoint)point { |
895 | 840 |
896 GURL url = webContents_ ? webContents_->GetURL() : GURL(); | 841 GURL url = webContents_ ? webContents_->GetURL() : GURL(); |
897 __block WebsiteSettingsBubbleController* weakSelf = self; | 842 __block WebsiteSettingsBubbleController* weakSelf = self; |
898 PermissionMenuModel::ChangeCallback callback = | 843 PermissionMenuModel::ChangeCallback callback = |
899 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { | 844 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 certificateId_ = identityInfo.cert_id; | 990 certificateId_ = identityInfo.cert_id; |
1046 if (certificateId_) { | 991 if (certificateId_) { |
1047 if (!certificateInfoButton_) { | 992 if (!certificateInfoButton_) { |
1048 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); | 993 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); |
1049 certificateInfoButton_ = [self addLinkButtonWithText:text | 994 certificateInfoButton_ = [self addLinkButtonWithText:text |
1050 toView:connectionTabContentView_]; | 995 toView:connectionTabContentView_]; |
1051 | 996 |
1052 [certificateInfoButton_ setTarget:self]; | 997 [certificateInfoButton_ setTarget:self]; |
1053 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; | 998 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; |
1054 } | 999 } |
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 } | |
1067 } else { | 1000 } else { |
1068 certificateInfoButton_ = nil; | 1001 certificateInfoButton_ = nil; |
1069 } | 1002 } |
1070 | 1003 |
1071 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( | 1004 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( |
1072 identityInfo.identity_status).ToNSImage()]; | 1005 identityInfo.identity_status).ToNSImage()]; |
1073 [identityStatusDescriptionField_ setStringValue: | 1006 [identityStatusDescriptionField_ setStringValue: |
1074 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; | 1007 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; |
1075 | 1008 |
1076 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( | 1009 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 [bubble_controller_ setPermissionInfo:permission_info_list]; | 1157 [bubble_controller_ setPermissionInfo:permission_info_list]; |
1225 } | 1158 } |
1226 | 1159 |
1227 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { | 1160 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { |
1228 [bubble_controller_ setFirstVisit:first_visit]; | 1161 [bubble_controller_ setFirstVisit:first_visit]; |
1229 } | 1162 } |
1230 | 1163 |
1231 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { | 1164 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { |
1232 [bubble_controller_ setSelectedTab:tab_id]; | 1165 [bubble_controller_ setSelectedTab:tab_id]; |
1233 } | 1166 } |
OLD | NEW |