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 #import "chrome/browser/ui/browser_dialogs.h" | 16 #import "chrome/browser/ui/browser_dialogs.h" |
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
20 #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" |
21 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 21 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
22 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 22 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
23 #include "chrome/browser/ui/website_settings/website_settings_utils.h" | 23 #include "chrome/browser/ui/website_settings/website_settings_utils.h" |
24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/cert_store.h" | 25 #include "content/public/browser/cert_store.h" |
26 #include "content/public/browser/page_navigator.h" | 26 #include "content/public/browser/page_navigator.h" |
| 27 #include "content/public/browser/ssl_host_state_delegate.h" |
27 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
31 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
32 #include "grit/ui_resources.h" | 33 #include "grit/ui_resources.h" |
33 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 34 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
34 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 35 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
35 #import "ui/base/cocoa/flipped_view.h" | 36 #import "ui/base/cocoa/flipped_view.h" |
| 37 #import "ui/base/cocoa/hover_button.h" |
36 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
37 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
38 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 40 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 // The default width of the window, in view coordinates. It may be larger to | 44 // The default width of the window, in view coordinates. It may be larger to |
43 // fit the content. | 45 // fit the content. |
44 const CGFloat kDefaultWindowWidth = 310; | 46 const CGFloat kDefaultWindowWidth = 310; |
45 | 47 |
(...skipping 462 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 content::SSLHostStateDelegate* delegate = |
| 524 webContents_->GetBrowserContext()->GetSSLHostStateDelegate(); |
| 525 if (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 hover button with the given text to |view|. |
| 857 - (NSButton*)addHoverButtonWithText:(NSString*)text toView:(NSView*)view { |
| 858 // Frame size is arbitrary; it will be adjusted by the layout tweaker. |
| 859 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10); |
| 860 base::scoped_nsobject<HoverButton> button( |
| 861 [[HoverButton alloc] initWithFrame:frame]); |
| 862 [button setTitle:text]; |
| 863 |
| 864 [button setButtonType:NSMomentaryPushInButton]; |
| 865 [button setBezelStyle:NSRegularSquareBezelStyle]; |
| 866 [view addSubview:button.get()]; |
| 867 |
| 868 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; |
| 869 return button.get(); |
| 870 } |
| 871 |
835 // Add a pop-up button for |permissionInfo| to the given view. | 872 // Add a pop-up button for |permissionInfo| to the given view. |
836 - (NSPopUpButton*)addPopUpButtonForPermission: | 873 - (NSPopUpButton*)addPopUpButtonForPermission: |
837 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 874 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
838 toView:(NSView*)view | 875 toView:(NSView*)view |
839 atPoint:(NSPoint)point { | 876 atPoint:(NSPoint)point { |
840 | 877 |
841 GURL url = webContents_ ? webContents_->GetURL() : GURL(); | 878 GURL url = webContents_ ? webContents_->GetURL() : GURL(); |
842 __block WebsiteSettingsBubbleController* weakSelf = self; | 879 __block WebsiteSettingsBubbleController* weakSelf = self; |
843 PermissionMenuModel::ChangeCallback callback = | 880 PermissionMenuModel::ChangeCallback callback = |
844 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { | 881 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 certificateId_ = identityInfo.cert_id; | 1027 certificateId_ = identityInfo.cert_id; |
991 if (certificateId_) { | 1028 if (certificateId_) { |
992 if (!certificateInfoButton_) { | 1029 if (!certificateInfoButton_) { |
993 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); | 1030 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); |
994 certificateInfoButton_ = [self addLinkButtonWithText:text | 1031 certificateInfoButton_ = [self addLinkButtonWithText:text |
995 toView:connectionTabContentView_]; | 1032 toView:connectionTabContentView_]; |
996 | 1033 |
997 [certificateInfoButton_ setTarget:self]; | 1034 [certificateInfoButton_ setTarget:self]; |
998 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; | 1035 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; |
999 } | 1036 } |
| 1037 |
| 1038 // Check if a security decision has been made, and if so, add a button to |
| 1039 // allow the user to retract their decision. |
| 1040 if (identityInfo.have_bypassed_ssl_error) { |
| 1041 NSString* text = l10n_util::GetNSString( |
| 1042 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON); |
| 1043 resetDecisionsButton_ = |
| 1044 [self addHoverButtonWithText:text toView:connectionTabContentView_]; |
| 1045 [resetDecisionsButton_ setTarget:self]; |
| 1046 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; |
| 1047 } |
1000 } else { | 1048 } else { |
1001 certificateInfoButton_ = nil; | 1049 certificateInfoButton_ = nil; |
1002 } | 1050 } |
1003 | 1051 |
1004 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( | 1052 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( |
1005 identityInfo.identity_status).ToNSImage()]; | 1053 identityInfo.identity_status).ToNSImage()]; |
1006 [identityStatusDescriptionField_ setStringValue: | 1054 [identityStatusDescriptionField_ setStringValue: |
1007 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; | 1055 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; |
1008 | 1056 |
1009 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( | 1057 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 [bubble_controller_ setPermissionInfo:permission_info_list]; | 1205 [bubble_controller_ setPermissionInfo:permission_info_list]; |
1158 } | 1206 } |
1159 | 1207 |
1160 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { | 1208 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { |
1161 [bubble_controller_ setFirstVisit:first_visit]; | 1209 [bubble_controller_ setFirstVisit:first_visit]; |
1162 } | 1210 } |
1163 | 1211 |
1164 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { | 1212 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { |
1165 [bubble_controller_ setSelectedTab:tab_id]; | 1213 [bubble_controller_ setSelectedTab:tab_id]; |
1166 } | 1214 } |
OLD | NEW |