| 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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/grit/theme_resources.h" | 32 #include "chrome/grit/theme_resources.h" |
| 33 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
| 34 #include "components/strings/grit/components_chromium_strings.h" | 34 #include "components/strings/grit/components_chromium_strings.h" |
| 35 #include "components/strings/grit/components_strings.h" | 35 #include "components/strings/grit/components_strings.h" |
| 36 #include "content/public/browser/page_navigator.h" | 36 #include "content/public/browser/page_navigator.h" |
| 37 #include "content/public/browser/ssl_host_state_delegate.h" | 37 #include "content/public/browser/ssl_host_state_delegate.h" |
| 38 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 39 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/common/url_constants.h" | 40 #include "content/public/common/url_constants.h" |
| 41 #include "extensions/common/constants.h" | 41 #include "extensions/common/constants.h" |
| 42 #include "skia/ext/skia_utils_mac.h" |
| 42 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 43 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 43 #include "ui/base/cocoa/cocoa_base_utils.h" | 44 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 44 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 45 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 45 #import "ui/base/cocoa/flipped_view.h" | 46 #import "ui/base/cocoa/flipped_view.h" |
| 46 #import "ui/base/cocoa/hover_image_button.h" | 47 #import "ui/base/cocoa/hover_image_button.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
| 49 #import "ui/gfx/mac/coordinate_conversion.h" | 50 #import "ui/gfx/mac/coordinate_conversion.h" |
| 50 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 51 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 51 #include "ui/resources/grit/ui_resources.h" | 52 #include "ui/resources/grit/ui_resources.h" |
| 52 | 53 |
| 53 using ChosenObjectInfoPtr = | 54 using ChosenObjectInfoPtr = |
| 54 std::unique_ptr<WebsiteSettingsUI::ChosenObjectInfo>; | 55 std::unique_ptr<WebsiteSettingsUI::ChosenObjectInfo>; |
| 55 using ChosenObjectDeleteCallback = | 56 using ChosenObjectDeleteCallback = |
| 56 base::Callback<void(const WebsiteSettingsUI::ChosenObjectInfo&)>; | 57 base::Callback<void(const WebsiteSettingsUI::ChosenObjectInfo&)>; |
| 57 | 58 |
| 58 namespace { | 59 namespace { |
| 59 | 60 |
| 60 /**************** General ****************/ | 61 /**************** General ****************/ |
| 61 | 62 |
| 62 // The default width of the window, in view coordinates. It may be larger to | 63 // The default width of the window, in view coordinates. It may be larger to |
| 63 // fit the content. | 64 // fit the content. |
| 64 const CGFloat kDefaultWindowWidth = 320; | 65 const CGFloat kDefaultWindowWidth = 320; |
| 65 | 66 |
| 66 // Padding around each section | 67 // Padding around each section |
| 67 const CGFloat kSectionVerticalPadding = 20; | 68 const CGFloat kSectionVerticalPadding = 20; |
| 68 const CGFloat kSectionHorizontalPadding = 16; | 69 const CGFloat kSectionHorizontalPadding = 16; |
| 69 | 70 |
| 70 // Spacing between the identity field and the security summary. | 71 // Links are buttons with invisible padding, so we need to move them back to |
| 71 const CGFloat kSpacingBeforeSecuritySummary = 2; | 72 // align with other text. |
| 73 const CGFloat kLinkButtonXAdjustment = 1; |
| 72 | 74 |
| 73 /**************** Security Section ****************/ | 75 /**************** Security Section ****************/ |
| 74 | 76 |
| 75 // Spacing between the security summary and the reset decisions button. | 77 // Spacing between security summary, security details, and cert decisions text. |
| 76 const CGFloat kSpacingBeforeResetDecisionsButton = 8; | 78 const CGFloat kSecurityParagraphSpacing = 12; |
| 77 | 79 |
| 78 /**************** Site Settings Section ****************/ | 80 /**************** Site Settings Section ****************/ |
| 79 | 81 |
| 80 // Spacing between parts of the site settings section. | 82 // Spacing between parts of the site settings section. |
| 81 const CGFloat kSiteSettingsSectionSpacing = 2; | 83 const CGFloat kSiteSettingsSectionSpacing = 2; |
| 82 | 84 |
| 83 // Square size of the permission images. | 85 // Square size of the permission images. |
| 84 const CGFloat kPermissionImageSize = 19; | 86 const CGFloat kPermissionImageSize = 19; |
| 85 | 87 |
| 86 // Square size of the permission delete button image. | 88 // Square size of the permission delete button image. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // |superview|. |superview| retains the new view. | 320 // |superview|. |superview| retains the new view. |
| 319 - (NSView*)addSecuritySectionToView:(NSView*)superview { | 321 - (NSView*)addSecuritySectionToView:(NSView*)superview { |
| 320 base::scoped_nsobject<NSView> securitySectionView( | 322 base::scoped_nsobject<NSView> securitySectionView( |
| 321 [[FlippedView alloc] initWithFrame:[superview frame]]); | 323 [[FlippedView alloc] initWithFrame:[superview frame]]); |
| 322 [superview addSubview:securitySectionView]; | 324 [superview addSubview:securitySectionView]; |
| 323 | 325 |
| 324 // Create a controlOrigin to place the text fields. The y value doesn't | 326 // Create a controlOrigin to place the text fields. The y value doesn't |
| 325 // matter, because the correct value is calculated in -performLayout. | 327 // matter, because the correct value is calculated in -performLayout. |
| 326 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); | 328 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); |
| 327 | 329 |
| 328 // Create a text field (empty for now) to show the site identity. | |
| 329 identityField_ = [self addText:base::string16() | |
| 330 withSize:[NSFont systemFontSize] | |
| 331 bold:YES | |
| 332 toView:securitySectionView | |
| 333 atPoint:controlOrigin]; | |
| 334 | |
| 335 // Create a text field for the security summary (private/not private/etc.). | 330 // Create a text field for the security summary (private/not private/etc.). |
| 336 securitySummaryField_ = [self addText:base::string16() | 331 securitySummaryField_ = [self addText:base::string16() |
| 332 withSize:[NSFont systemFontSize] |
| 333 bold:NO |
| 334 toView:securitySectionView |
| 335 atPoint:controlOrigin]; |
| 336 |
| 337 securityDetailsField_ = [self addText:base::string16() |
| 337 withSize:[NSFont smallSystemFontSize] | 338 withSize:[NSFont smallSystemFontSize] |
| 338 bold:NO | 339 bold:NO |
| 339 toView:securitySectionView | 340 toView:securitySectionView |
| 340 atPoint:controlOrigin]; | 341 atPoint:controlOrigin]; |
| 341 | 342 |
| 342 resetDecisionsButton_ = nil; // This will be created only if necessary. | 343 // These will be created only if necessary. |
| 344 resetDecisionsField_ = nil; |
| 345 resetDecisionsButton_ = nil; |
| 343 | 346 |
| 344 NSString* securityDetailsButtonText = | 347 NSString* securityDetailsButtonText = |
| 345 l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_DETAILS_LINK); | 348 l10n_util::GetNSString(IDS_WEBSITE_SETTINGS_DETAILS_LINK); |
| 346 // Note: The security details button may be removed from the superview in | 349 // Note: The security details button may be removed from the superview in |
| 347 // -performLayout in order to hide it (depending on the connection). | 350 // -performLayout in order to hide it (depending on the connection). |
| 348 securityDetailsButton_ = [self addLinkButtonWithText:securityDetailsButtonText | 351 securityDetailsButton_ = [self addLinkButtonWithText:securityDetailsButtonText |
| 349 toView:securitySectionView]; | 352 toView:securitySectionView]; |
| 350 [securityDetailsButton_ setTarget:self]; | 353 [securityDetailsButton_ setTarget:self]; |
| 351 [securityDetailsButton_ setAction:@selector(showSecurityDetails:)]; | 354 [securityDetailsButton_ setAction:@selector(showSecurityDetails:)]; |
| 352 | 355 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 482 |
| 480 [contentView_ setFrame:NSMakeRect(0, 0, NSWidth([contentView_ frame]), yPos)]; | 483 [contentView_ setFrame:NSMakeRect(0, 0, NSWidth([contentView_ frame]), yPos)]; |
| 481 | 484 |
| 482 [self sizeAndPositionWindow]; | 485 [self sizeAndPositionWindow]; |
| 483 } | 486 } |
| 484 | 487 |
| 485 - (void)layoutSecuritySection { | 488 - (void)layoutSecuritySection { |
| 486 // Start the layout with the first element. Margins are handled by the caller. | 489 // Start the layout with the first element. Margins are handled by the caller. |
| 487 CGFloat yPos = 0; | 490 CGFloat yPos = 0; |
| 488 | 491 |
| 489 [self sizeTextFieldHeightToFit:identityField_]; | 492 [self sizeTextFieldHeightToFit:securitySummaryField_]; |
| 490 yPos = [self setYPositionOfView:identityField_ | 493 yPos = [self setYPositionOfView:securitySummaryField_ |
| 491 to:yPos + kSectionVerticalPadding]; | 494 to:yPos + kSectionVerticalPadding]; |
| 492 | 495 |
| 493 [self sizeTextFieldHeightToFit:securitySummaryField_]; | 496 [self sizeTextFieldHeightToFit:securityDetailsField_]; |
| 494 yPos = [self setYPositionOfView:securitySummaryField_ | 497 yPos = [self setYPositionOfView:securityDetailsField_ |
| 495 to:yPos + kSpacingBeforeSecuritySummary]; | 498 to:yPos + kSecurityParagraphSpacing]; |
| 496 | 499 |
| 497 if (isDevToolsDisabled_ && !certificate_) { | 500 if (isDevToolsDisabled_ && !certificate_) { |
| 498 // -removeFromSuperview is idempotent. | 501 // -removeFromSuperview is idempotent. |
| 499 [securityDetailsButton_ removeFromSuperview]; | 502 [securityDetailsButton_ removeFromSuperview]; |
| 500 } else { | 503 } else { |
| 501 // -addSubview is idempotent. | 504 // -addSubview is idempotent. |
| 502 [securitySectionView_ addSubview:securityDetailsButton_]; | 505 [securitySectionView_ addSubview:securityDetailsButton_]; |
| 503 yPos = [self setYPositionOfView:securityDetailsButton_ to:yPos]; | 506 [securityDetailsButton_ |
| 507 setFrameOrigin:NSMakePoint( |
| 508 kSectionHorizontalPadding - kLinkButtonXAdjustment, |
| 509 yPos)]; |
| 510 yPos = NSMaxY([securityDetailsButton_ frame]); |
| 504 } | 511 } |
| 505 | 512 |
| 506 if (resetDecisionsButton_) { | 513 if (resetDecisionsButton_) { |
| 507 yPos = [self setYPositionOfView:resetDecisionsButton_ | 514 DCHECK(resetDecisionsField_); |
| 508 to:yPos + kSpacingBeforeResetDecisionsButton]; | 515 yPos = [self setYPositionOfView:resetDecisionsField_ |
| 516 to:yPos + kSecurityParagraphSpacing]; |
| 517 [resetDecisionsButton_ |
| 518 setFrameOrigin:NSMakePoint(NSMinX([resetDecisionsButton_ frame]) - |
| 519 kLinkButtonXAdjustment, |
| 520 yPos)]; |
| 521 yPos = NSMaxY([resetDecisionsButton_ frame]); |
| 509 } | 522 } |
| 510 | 523 |
| 511 // Resize the height based on contents. | 524 // Resize the height based on contents. |
| 512 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding]; | 525 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding]; |
| 513 } | 526 } |
| 514 | 527 |
| 515 - (void)layoutSiteSettingsSection { | 528 - (void)layoutSiteSettingsSection { |
| 516 // Start the layout with the first element. Margins are handled by the caller. | 529 // Start the layout with the first element. Margins are handled by the caller. |
| 517 CGFloat yPos = 0; | 530 CGFloat yPos = 0; |
| 518 | 531 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 [button setFrame:buttonFrame]; | 683 [button setFrame:buttonFrame]; |
| 671 [button setButtonType:NSMomentaryPushInButton]; | 684 [button setButtonType:NSMomentaryPushInButton]; |
| 672 [button setBezelStyle:NSRegularSquareBezelStyle]; | 685 [button setBezelStyle:NSRegularSquareBezelStyle]; |
| 673 [view addSubview:button.get()]; | 686 [view addSubview:button.get()]; |
| 674 | 687 |
| 675 return button.get(); | 688 return button.get(); |
| 676 } | 689 } |
| 677 | 690 |
| 678 // Set the content of the identity and identity status fields. | 691 // Set the content of the identity and identity status fields. |
| 679 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { | 692 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { |
| 680 [identityField_ | 693 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = |
| 681 setStringValue:base::SysUTF8ToNSString(identityInfo.site_identity)]; | 694 identityInfo.GetSecurityDescription(); |
| 682 [securitySummaryField_ setStringValue:base::SysUTF16ToNSString( | 695 [securitySummaryField_ |
| 683 identityInfo.GetSecuritySummary())]; | 696 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; |
| 697 |
| 698 [securityDetailsField_ |
| 699 setStringValue:SysUTF16ToNSString(security_description->details)]; |
| 684 | 700 |
| 685 certificate_ = identityInfo.certificate; | 701 certificate_ = identityInfo.certificate; |
| 686 | 702 |
| 687 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { | 703 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { |
| 688 NSString* text = l10n_util::GetNSString( | 704 resetDecisionsField_ = |
| 689 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON); | 705 [self addText:base::string16() |
| 706 withSize:[NSFont smallSystemFontSize] |
| 707 bold:NO |
| 708 toView:securitySectionView_ |
| 709 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)]; |
| 710 [resetDecisionsField_ |
| 711 setStringValue:l10n_util::GetNSString( |
| 712 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)]; |
| 713 [self sizeTextFieldHeightToFit:resetDecisionsField_]; |
| 714 |
| 690 resetDecisionsButton_ = | 715 resetDecisionsButton_ = |
| 691 [self addButtonWithText:text toView:securitySectionView_]; | 716 [self addLinkButtonWithText: |
| 717 l10n_util::GetNSString( |
| 718 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON) |
| 719 toView:securitySectionView_]; |
| 692 [resetDecisionsButton_ setTarget:self]; | 720 [resetDecisionsButton_ setTarget:self]; |
| 693 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; | 721 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; |
| 694 } | 722 } |
| 695 | 723 |
| 696 [self performLayout]; | 724 [self performLayout]; |
| 697 } | 725 } |
| 698 | 726 |
| 699 // Add a pop-up button for |permissionInfo| to the given view. | 727 // Add a pop-up button for |permissionInfo| to the given view. |
| 700 - (NSPopUpButton*)addPopUpButtonForPermission: | 728 - (NSPopUpButton*)addPopUpButtonForPermission: |
| 701 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 729 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 void WebsiteSettingsUIBridge::SetPermissionInfo( | 1236 void WebsiteSettingsUIBridge::SetPermissionInfo( |
| 1209 const PermissionInfoList& permission_info_list, | 1237 const PermissionInfoList& permission_info_list, |
| 1210 const ChosenObjectInfoList& chosen_object_info_list) { | 1238 const ChosenObjectInfoList& chosen_object_info_list) { |
| 1211 [bubble_controller_ setPermissionInfo:permission_info_list | 1239 [bubble_controller_ setPermissionInfo:permission_info_list |
| 1212 andChosenObjects:chosen_object_info_list]; | 1240 andChosenObjects:chosen_object_info_list]; |
| 1213 } | 1241 } |
| 1214 | 1242 |
| 1215 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { | 1243 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { |
| 1216 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) | 1244 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) |
| 1217 } | 1245 } |
| OLD | NEW |