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

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.mm

Issue 418133012: Add button to page info to revoke user certificate decisions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address pkasting comments Created 6 years, 4 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 | Annotate | Revision Log
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/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.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
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::SSLHostState(webContents_->GetBrowserContext()).
524 RevokeAllowAndDenyPreferencesHard(presenter_->site_url().host());
525 [self close];
526 }
527
518 // Handler for the link to show help information about the connection tab. 528 // Handler for the link to show help information about the connection tab.
519 - (void)showHelpPage:(id)sender { 529 - (void)showHelpPage:(id)sender {
520 webContents_->OpenURL(content::OpenURLParams( 530 webContents_->OpenURL(content::OpenURLParams(
521 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), 531 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
522 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); 532 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false));
523 } 533 }
524 534
525 // Create the contents of the Connection tab and add it to the given tab view. 535 // 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. 536 // Returns a weak reference to the tab view item's view.
527 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView { 537 - (NSView*)addConnectionTabToTabView:(NSTabView*)tabView {
(...skipping 26 matching lines...) Expand all
554 connectionStatusIcon_ = [self addImageWithSize:imageSize 564 connectionStatusIcon_ = [self addImageWithSize:imageSize
555 toView:contentView 565 toView:contentView
556 atPoint:imagePosition]; 566 atPoint:imagePosition];
557 connectionStatusDescriptionField_ = 567 connectionStatusDescriptionField_ =
558 [self addText:base::string16() 568 [self addText:base::string16()
559 withSize:[NSFont smallSystemFontSize] 569 withSize:[NSFont smallSystemFontSize]
560 bold:NO 570 bold:NO
561 toView:contentView.get() 571 toView:contentView.get()
562 atPoint:textPosition]; 572 atPoint:textPosition];
563 certificateInfoButton_ = nil; // This will be created only if necessary. 573 certificateInfoButton_ = nil; // This will be created only if necessary.
574 resetDecisionsButton_ = nil; // This will be created only if necessary.
564 separatorAfterConnection_ = [self addSeparatorToView:contentView]; 575 separatorAfterConnection_ = [self addSeparatorToView:contentView];
565 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable]; 576 [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable];
566 577
567 firstVisitIcon_ = [self addImageWithSize:imageSize 578 firstVisitIcon_ = [self addImageWithSize:imageSize
568 toView:contentView 579 toView:contentView
569 atPoint:imagePosition]; 580 atPoint:imagePosition];
570 firstVisitHeaderField_ = 581 firstVisitHeaderField_ =
571 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE) 582 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE)
572 withSize:[NSFont smallSystemFontSize] 583 withSize:[NSFont smallSystemFontSize]
573 bold:YES 584 bold:YES
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]), 663 yPos = std::max(NSMaxY([identityStatusDescriptionField_ frame]),
653 NSMaxY([identityStatusIcon_ frame])); 664 NSMaxY([identityStatusIcon_ frame]));
654 if (certificateInfoButton_) { 665 if (certificateInfoButton_) {
655 NSRect certificateButtonFrame = [certificateInfoButton_ frame]; 666 NSRect certificateButtonFrame = [certificateInfoButton_ frame];
656 certificateButtonFrame.origin.x = NSMinX( 667 certificateButtonFrame.origin.x = NSMinX(
657 [identityStatusDescriptionField_ frame]); 668 [identityStatusDescriptionField_ frame]);
658 certificateButtonFrame.origin.y = yPos + kVerticalSpacing; 669 certificateButtonFrame.origin.y = yPos + kVerticalSpacing;
659 [certificateInfoButton_ setFrame:certificateButtonFrame]; 670 [certificateInfoButton_ setFrame:certificateButtonFrame];
660 yPos = NSMaxY(certificateButtonFrame); 671 yPos = NSMaxY(certificateButtonFrame);
661 } 672 }
673 if (resetDecisionsButton_) {
674 NSRect resetDecisionsButtonFrame = [resetDecisionsButton_ frame];
675 resetDecisionsButtonFrame.origin.x =
676 NSMinX([identityStatusDescriptionField_ frame]);
677 resetDecisionsButtonFrame.origin.y = yPos + kVerticalSpacing;
678 [resetDecisionsButton_ setFrame:resetDecisionsButtonFrame];
679 yPos = NSMaxY(resetDecisionsButtonFrame);
680 }
662 yPos = [self setYPositionOfView:separatorAfterIdentity_ 681 yPos = [self setYPositionOfView:separatorAfterIdentity_
663 to:yPos + kVerticalSpacing]; 682 to:yPos + kVerticalSpacing];
664 yPos += kVerticalSpacing; 683 yPos += kVerticalSpacing;
665 684
666 // Lay out the connection status section. 685 // Lay out the connection status section.
667 [self sizeTextFieldHeightToFit:connectionStatusDescriptionField_]; 686 [self sizeTextFieldHeightToFit:connectionStatusDescriptionField_];
668 [self setYPositionOfView:connectionStatusIcon_ to:yPos]; 687 [self setYPositionOfView:connectionStatusIcon_ to:yPos];
669 [self setYPositionOfView:connectionStatusDescriptionField_ to:yPos]; 688 [self setYPositionOfView:connectionStatusDescriptionField_ to:yPos];
670 yPos = std::max(NSMaxY([connectionStatusDescriptionField_ frame]), 689 yPos = std::max(NSMaxY([connectionStatusDescriptionField_ frame]),
671 NSMaxY([connectionStatusIcon_ frame])); 690 NSMaxY([connectionStatusIcon_ frame]));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 [cell setControlSize:NSSmallControlSize]; 844 [cell setControlSize:NSSmallControlSize];
826 [button setCell:cell.get()]; 845 [button setCell:cell.get()];
827 [button setButtonType:NSMomentaryPushInButton]; 846 [button setButtonType:NSMomentaryPushInButton];
828 [button setBezelStyle:NSRegularSquareBezelStyle]; 847 [button setBezelStyle:NSRegularSquareBezelStyle];
829 [view addSubview:button.get()]; 848 [view addSubview:button.get()];
830 849
831 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; 850 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()];
832 return button.get(); 851 return button.get();
833 } 852 }
834 853
854 // Add a hover button with the given text to |view|.
855 - (NSButton*)addHoverButtonWithText:(NSString*)text toView:(NSView*)view {
856 // Frame size is arbitrary; it will be adjusted by the layout tweaker.
857 NSRect frame = NSMakeRect(kFramePadding, 0, 100, 10);
858 base::scoped_nsobject<HoverButton> button(
859 [[HoverButton alloc] initWithFrame:frame]);
860 [button setTitle:text];
861
862 [button setButtonType:NSMomentaryPushInButton];
863 [button setBezelStyle:NSRegularSquareBezelStyle];
864 [view addSubview:button.get()];
865
866 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()];
867 return button.get();
868 }
869
835 // Add a pop-up button for |permissionInfo| to the given view. 870 // Add a pop-up button for |permissionInfo| to the given view.
836 - (NSPopUpButton*)addPopUpButtonForPermission: 871 - (NSPopUpButton*)addPopUpButtonForPermission:
837 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo 872 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
838 toView:(NSView*)view 873 toView:(NSView*)view
839 atPoint:(NSPoint)point { 874 atPoint:(NSPoint)point {
840 875
841 GURL url = webContents_ ? webContents_->GetURL() : GURL(); 876 GURL url = webContents_ ? webContents_->GetURL() : GURL();
842 __block WebsiteSettingsBubbleController* weakSelf = self; 877 __block WebsiteSettingsBubbleController* weakSelf = self;
843 PermissionMenuModel::ChangeCallback callback = 878 PermissionMenuModel::ChangeCallback callback =
844 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { 879 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 certificateId_ = identityInfo.cert_id; 1025 certificateId_ = identityInfo.cert_id;
991 if (certificateId_) { 1026 if (certificateId_) {
992 if (!certificateInfoButton_) { 1027 if (!certificateInfoButton_) {
993 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON); 1028 NSString* text = l10n_util::GetNSString(IDS_PAGEINFO_CERT_INFO_BUTTON);
994 certificateInfoButton_ = [self addLinkButtonWithText:text 1029 certificateInfoButton_ = [self addLinkButtonWithText:text
995 toView:connectionTabContentView_]; 1030 toView:connectionTabContentView_];
996 1031
997 [certificateInfoButton_ setTarget:self]; 1032 [certificateInfoButton_ setTarget:self];
998 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)]; 1033 [certificateInfoButton_ setAction:@selector(showCertificateInfo:)];
999 } 1034 }
1035
1036 // Check if a security decision has been made, and if so, add a button to
1037 // allow the user to retract their decision.
1038 if (identityInfo.certificate_decision_made) {
1039 NSString* text = l10n_util::GetNSString(
1040 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON);
1041 resetDecisionsButton_ =
1042 [self addHoverButtonWithText:text toView:connectionTabContentView_];
1043 [resetDecisionsButton_ setTarget:self];
1044 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)];
1045 }
1000 } else { 1046 } else {
1001 certificateInfoButton_ = nil; 1047 certificateInfoButton_ = nil;
1002 } 1048 }
1003 1049
1004 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon( 1050 [identityStatusIcon_ setImage:WebsiteSettingsUI::GetIdentityIcon(
1005 identityInfo.identity_status).ToNSImage()]; 1051 identityInfo.identity_status).ToNSImage()];
1006 [identityStatusDescriptionField_ setStringValue: 1052 [identityStatusDescriptionField_ setStringValue:
1007 base::SysUTF8ToNSString(identityInfo.identity_status_description)]; 1053 base::SysUTF8ToNSString(identityInfo.identity_status_description)];
1008 1054
1009 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon( 1055 [connectionStatusIcon_ setImage:WebsiteSettingsUI::GetConnectionIcon(
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 [bubble_controller_ setPermissionInfo:permission_info_list]; 1203 [bubble_controller_ setPermissionInfo:permission_info_list];
1158 } 1204 }
1159 1205
1160 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) { 1206 void WebsiteSettingsUIBridge::SetFirstVisit(const base::string16& first_visit) {
1161 [bubble_controller_ setFirstVisit:first_visit]; 1207 [bubble_controller_ setFirstVisit:first_visit];
1162 } 1208 }
1163 1209
1164 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1210 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1165 [bubble_controller_ setSelectedTab:tab_id]; 1211 [bubble_controller_ setSelectedTab:tab_id];
1166 } 1212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698