| 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/page_info/website_settings_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info/website_settings_bubble_controller.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 url:(const GURL&)url { | 200 url:(const GURL&)url { |
| 201 DCHECK(parentWindow); | 201 DCHECK(parentWindow); |
| 202 | 202 |
| 203 webContents_ = webContents; | 203 webContents_ = webContents; |
| 204 permissionsPresent_ = NO; | 204 permissionsPresent_ = NO; |
| 205 url_ = url; | 205 url_ = url; |
| 206 | 206 |
| 207 // Use an arbitrary height; it will be changed in performLayout. | 207 // Use an arbitrary height; it will be changed in performLayout. |
| 208 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); | 208 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); |
| 209 // Create an empty window into which content is placed. | 209 // Create an empty window into which content is placed. |
| 210 base::scoped_nsobject<InfoBubbleWindow> window( | 210 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
| 211 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 211 initWithContentRect:contentRect |
| 212 styleMask:NSBorderlessWindowMask | 212 styleMask:NSBorderlessWindowMask |
| 213 backing:NSBackingStoreBuffered | 213 backing:NSBackingStoreBuffered |
| 214 defer:NO]); | 214 defer:NO]); |
| 215 | 215 |
| 216 if ((self = [super initWithWindow:window.get() | 216 if ((self = [super initWithWindow:window.get() |
| 217 parentWindow:parentWindow | 217 parentWindow:parentWindow |
| 218 anchoredAt:NSZeroPoint])) { | 218 anchoredAt:NSZeroPoint])) { |
| 219 [[self bubble] setArrowLocation:info_bubble::kTopLeading]; | 219 [[self bubble] setArrowLocation:info_bubble::kTopLeading]; |
| 220 | 220 |
| 221 // Create the container view that uses flipped coordinates. | 221 // Create the container view that uses flipped coordinates. |
| 222 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); | 222 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); |
| 223 contentView_.reset( | 223 contentView_.reset([[FlippedView alloc] initWithFrame:contentFrame]); |
| 224 [[FlippedView alloc] initWithFrame:contentFrame]); | |
| 225 | 224 |
| 226 // Replace the window's content. | 225 // Replace the window's content. |
| 227 [[[self window] contentView] setSubviews: | 226 [[[self window] contentView] |
| 228 [NSArray arrayWithObject:contentView_.get()]]; | 227 setSubviews:[NSArray arrayWithObject:contentView_.get()]]; |
| 229 | 228 |
| 230 if (IsInternalURL(url_)) { | 229 if (IsInternalURL(url_)) { |
| 231 [self initializeContentsForInternalPage:url_]; | 230 [self initializeContentsForInternalPage:url_]; |
| 232 } else { | 231 } else { |
| 233 [self initializeContents]; | 232 [self initializeContents]; |
| 234 } | 233 } |
| 235 | 234 |
| 236 bridge_.reset(bridge); | 235 bridge_.reset(bridge); |
| 237 bridge_->set_bubble_controller(self); | 236 bridge_->set_bubble_controller(self); |
| 238 } | 237 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 // results when the image, at 26x26, was taller than (or just slightly | 298 // results when the image, at 26x26, was taller than (or just slightly |
| 300 // shorter) than the text, but produced incorrect results once the icon | 299 // shorter) than the text, but produced incorrect results once the icon |
| 301 // shrank to 16x16. The icon should now always be shorter than the text. | 300 // shrank to 16x16. The icon should now always be shorter than the text. |
| 302 // See crbug.com/572044 . | 301 // See crbug.com/572044 . |
| 303 NSRect textFrame = [textField frame]; | 302 NSRect textFrame = [textField frame]; |
| 304 imageFrame.origin.y += (NSHeight(textFrame) - NSHeight(imageFrame)) / 2; | 303 imageFrame.origin.y += (NSHeight(textFrame) - NSHeight(imageFrame)) / 2; |
| 305 [imageView setFrame:imageFrame]; | 304 [imageView setFrame:imageFrame]; |
| 306 | 305 |
| 307 // Adjust the contentView to fit everything. | 306 // Adjust the contentView to fit everything. |
| 308 CGFloat maxY = std::max(NSMaxY(imageFrame), NSMaxY(textFrame)); | 307 CGFloat maxY = std::max(NSMaxY(imageFrame), NSMaxY(textFrame)); |
| 309 [contentView_ setFrame:NSMakeRect( | 308 [contentView_ setFrame:NSMakeRect(0, 0, [self defaultWindowWidth], |
| 310 0, 0, [self defaultWindowWidth], maxY + kInternalPageFramePadding)]; | 309 maxY + kInternalPageFramePadding)]; |
| 311 | 310 |
| 312 [self sizeAndPositionWindow]; | 311 [self sizeAndPositionWindow]; |
| 313 } | 312 } |
| 314 | 313 |
| 315 // Create the subviews for the website settings bubble. | 314 // Create the subviews for the website settings bubble. |
| 316 - (void)initializeContents { | 315 - (void)initializeContents { |
| 317 securitySectionView_ = [self addSecuritySectionToView:contentView_]; | 316 securitySectionView_ = [self addSecuritySectionToView:contentView_]; |
| 318 separatorAfterSecuritySection_ = [self addSeparatorToView:contentView_]; | 317 separatorAfterSecuritySection_ = [self addSeparatorToView:contentView_]; |
| 319 siteSettingsSectionView_ = [self addSiteSettingsSectionToView:contentView_]; | 318 siteSettingsSectionView_ = [self addSiteSettingsSectionToView:contentView_]; |
| 320 | 319 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 342 securityDetailsField_ = [self addText:base::string16() | 341 securityDetailsField_ = [self addText:base::string16() |
| 343 withSize:[NSFont smallSystemFontSize] | 342 withSize:[NSFont smallSystemFontSize] |
| 344 bold:NO | 343 bold:NO |
| 345 toView:securitySectionView | 344 toView:securitySectionView |
| 346 atPoint:controlOrigin]; | 345 atPoint:controlOrigin]; |
| 347 | 346 |
| 348 // These will be created only if necessary. | 347 // These will be created only if necessary. |
| 349 resetDecisionsField_ = nil; | 348 resetDecisionsField_ = nil; |
| 350 resetDecisionsButton_ = nil; | 349 resetDecisionsButton_ = nil; |
| 351 | 350 |
| 352 NSString* connectionHelpButtonText = | 351 NSString* connectionHelpButtonText = l10n_util::GetNSString(IDS_LEARN_MORE); |
| 353 l10n_util::GetNSString(IDS_LEARN_MORE); | |
| 354 connectionHelpButton_ = [self addLinkButtonWithText:connectionHelpButtonText | 352 connectionHelpButton_ = [self addLinkButtonWithText:connectionHelpButtonText |
| 355 toView:securitySectionView]; | 353 toView:securitySectionView]; |
| 356 [connectionHelpButton_ setTarget:self]; | 354 [connectionHelpButton_ setTarget:self]; |
| 357 [connectionHelpButton_ setAction:@selector(openConnectionHelp:)]; | 355 [connectionHelpButton_ setAction:@selector(openConnectionHelp:)]; |
| 358 | 356 |
| 359 return securitySectionView.get(); | 357 return securitySectionView.get(); |
| 360 } | 358 } |
| 361 | 359 |
| 362 // Create and return a subview for the site settings and add it to the given | 360 // Create and return a subview for the site settings and add it to the given |
| 363 // |superview|. |superview| retains the new view. | 361 // |superview|. |superview| retains the new view. |
| 364 - (NSView*)addSiteSettingsSectionToView:(NSView*)superview { | 362 - (NSView*)addSiteSettingsSectionToView:(NSView*)superview { |
| 365 base::scoped_nsobject<NSView> siteSettingsSectionView( | 363 base::scoped_nsobject<NSView> siteSettingsSectionView( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 465 } |
| 468 | 466 |
| 469 - (void)setHeightOfView:(NSView*)view to:(CGFloat)height { | 467 - (void)setHeightOfView:(NSView*)view to:(CGFloat)height { |
| 470 [view setFrameSize:NSMakeSize(NSWidth([view frame]), height)]; | 468 [view setFrameSize:NSMakeSize(NSWidth([view frame]), height)]; |
| 471 } | 469 } |
| 472 | 470 |
| 473 // Layout all of the controls in the window. This should be called whenever | 471 // Layout all of the controls in the window. This should be called whenever |
| 474 // the content has changed. | 472 // the content has changed. |
| 475 - (void)performLayout { | 473 - (void)performLayout { |
| 476 // Make the content at least as wide as the permissions view. | 474 // Make the content at least as wide as the permissions view. |
| 477 CGFloat contentWidth = std::max([self defaultWindowWidth], | 475 CGFloat contentWidth = |
| 478 NSWidth([permissionsView_ frame])); | 476 std::max([self defaultWindowWidth], NSWidth([permissionsView_ frame])); |
| 479 | 477 |
| 480 // Set the width of the content view now, so that all the text fields will | 478 // Set the width of the content view now, so that all the text fields will |
| 481 // be sized to fit before their heights and vertical positions are adjusted. | 479 // be sized to fit before their heights and vertical positions are adjusted. |
| 482 [self setWidthOfView:contentView_ to:contentWidth]; | 480 [self setWidthOfView:contentView_ to:contentWidth]; |
| 483 [self setWidthOfView:securitySectionView_ to:contentWidth]; | 481 [self setWidthOfView:securitySectionView_ to:contentWidth]; |
| 484 [self setWidthOfView:siteSettingsSectionView_ to:contentWidth]; | 482 [self setWidthOfView:siteSettingsSectionView_ to:contentWidth]; |
| 485 | 483 |
| 486 CGFloat yPos = 0; | 484 CGFloat yPos = 0; |
| 487 | 485 |
| 488 [self layoutSecuritySection]; | 486 [self layoutSecuritySection]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 503 CGFloat yPos = 0; | 501 CGFloat yPos = 0; |
| 504 | 502 |
| 505 [self sizeTextFieldHeightToFit:securitySummaryField_]; | 503 [self sizeTextFieldHeightToFit:securitySummaryField_]; |
| 506 yPos = [self setYPositionOfView:securitySummaryField_ | 504 yPos = [self setYPositionOfView:securitySummaryField_ |
| 507 to:yPos + kSectionVerticalPadding]; | 505 to:yPos + kSectionVerticalPadding]; |
| 508 | 506 |
| 509 [self sizeTextFieldHeightToFit:securityDetailsField_]; | 507 [self sizeTextFieldHeightToFit:securityDetailsField_]; |
| 510 yPos = [self setYPositionOfView:securityDetailsField_ | 508 yPos = [self setYPositionOfView:securityDetailsField_ |
| 511 to:yPos + kSecurityParagraphSpacing]; | 509 to:yPos + kSecurityParagraphSpacing]; |
| 512 | 510 |
| 513 [connectionHelpButton_ | 511 [connectionHelpButton_ setFrameOrigin:NSMakePoint(kSectionHorizontalPadding - |
| 514 setFrameOrigin:NSMakePoint( | 512 kLinkButtonXAdjustment, |
| 515 kSectionHorizontalPadding - kLinkButtonXAdjustment, | 513 yPos)]; |
| 516 yPos)]; | |
| 517 yPos = NSMaxY([connectionHelpButton_ frame]); | 514 yPos = NSMaxY([connectionHelpButton_ frame]); |
| 518 | 515 |
| 519 if (resetDecisionsButton_) { | 516 if (resetDecisionsButton_) { |
| 520 DCHECK(resetDecisionsField_); | 517 DCHECK(resetDecisionsField_); |
| 521 yPos = [self setYPositionOfView:resetDecisionsField_ | 518 yPos = [self setYPositionOfView:resetDecisionsField_ |
| 522 to:yPos + kSecurityParagraphSpacing]; | 519 to:yPos + kSecurityParagraphSpacing]; |
| 523 [resetDecisionsButton_ | 520 [resetDecisionsButton_ |
| 524 setFrameOrigin:NSMakePoint(NSMinX([resetDecisionsButton_ frame]) - | 521 setFrameOrigin:NSMakePoint(NSMinX([resetDecisionsButton_ frame]) - |
| 525 kLinkButtonXAdjustment, | 522 kLinkButtonXAdjustment, |
| 526 yPos)]; | 523 yPos)]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 547 | 544 |
| 548 // Resize the height based on contents. | 545 // Resize the height based on contents. |
| 549 [self setHeightOfView:siteSettingsSectionView_ | 546 [self setHeightOfView:siteSettingsSectionView_ |
| 550 to:yPos + kSectionVerticalPadding]; | 547 to:yPos + kSectionVerticalPadding]; |
| 551 } | 548 } |
| 552 | 549 |
| 553 // Adjust the size of the window to match the size of the content, and position | 550 // Adjust the size of the window to match the size of the content, and position |
| 554 // the bubble anchor appropriately. | 551 // the bubble anchor appropriately. |
| 555 - (void)sizeAndPositionWindow { | 552 - (void)sizeAndPositionWindow { |
| 556 NSRect windowFrame = [contentView_ frame]; | 553 NSRect windowFrame = [contentView_ frame]; |
| 557 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size | 554 windowFrame.size = |
| 558 toView:nil]; | 555 [[[self window] contentView] convertSize:windowFrame.size toView:nil]; |
| 559 // Adjust the origin by the difference in height. | 556 // Adjust the origin by the difference in height. |
| 560 windowFrame.origin = [[self window] frame].origin; | 557 windowFrame.origin = [[self window] frame].origin; |
| 561 windowFrame.origin.y -= NSHeight(windowFrame) - | 558 windowFrame.origin.y -= |
| 562 NSHeight([[self window] frame]); | 559 NSHeight(windowFrame) - NSHeight([[self window] frame]); |
| 563 | 560 |
| 564 // Resize the window. Only animate if the window is visible, otherwise it | 561 // Resize the window. Only animate if the window is visible, otherwise it |
| 565 // could be "growing" while it's opening, looking awkward. | 562 // could be "growing" while it's opening, looking awkward. |
| 566 [[self window] setFrame:windowFrame | 563 [[self window] setFrame:windowFrame |
| 567 display:YES | 564 display:YES |
| 568 animate:[[self window] isVisible]]; | 565 animate:[[self window] isVisible]]; |
| 569 | 566 |
| 570 // Adjust the anchor for the bubble. | 567 // Adjust the anchor for the bubble. |
| 571 [self setAnchorPoint:AnchorPointForWindow([self parentWindow])]; | 568 [self setAnchorPoint:AnchorPointForWindow([self parentWindow])]; |
| 572 } | 569 } |
| 573 | 570 |
| 574 // Sets properties on the given |field| to act as the title or description | 571 // Sets properties on the given |field| to act as the title or description |
| 575 // labels in the bubble. | 572 // labels in the bubble. |
| 576 - (void)configureTextFieldAsLabel:(NSTextField*)textField { | 573 - (void)configureTextFieldAsLabel:(NSTextField*)textField { |
| 577 [textField setEditable:NO]; | 574 [textField setEditable:NO]; |
| 578 [textField setSelectable:YES]; | 575 [textField setSelectable:YES]; |
| 579 [textField setDrawsBackground:NO]; | 576 [textField setDrawsBackground:NO]; |
| 580 [textField setBezeled:NO]; | 577 [textField setBezeled:NO]; |
| 581 } | 578 } |
| 582 | 579 |
| 583 // Adjust the height of the given text field to match its text. | 580 // Adjust the height of the given text field to match its text. |
| 584 - (void)sizeTextFieldHeightToFit:(NSTextField*)textField { | 581 - (void)sizeTextFieldHeightToFit:(NSTextField*)textField { |
| 585 NSRect frame = [textField frame]; | 582 NSRect frame = [textField frame]; |
| 586 frame.size.height += | 583 frame.size.height += |
| 587 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: | 584 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:textField]; |
| 588 textField]; | |
| 589 [textField setFrame:frame]; | 585 [textField setFrame:frame]; |
| 590 } | 586 } |
| 591 | 587 |
| 592 // Create a new text field and add it to the given array of subviews. | 588 // Create a new text field and add it to the given array of subviews. |
| 593 // The array will retain a reference to the object. | 589 // The array will retain a reference to the object. |
| 594 - (NSTextField*)addText:(const base::string16&)text | 590 - (NSTextField*)addText:(const base::string16&)text |
| 595 withSize:(CGFloat)fontSize | 591 withSize:(CGFloat)fontSize |
| 596 bold:(BOOL)bold | 592 bold:(BOOL)bold |
| 597 toView:(NSView*)view | 593 toView:(NSView*)view |
| 598 atPoint:(NSPoint)point { | 594 atPoint:(NSPoint)point { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = | 691 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = |
| 696 identityInfo.GetSecurityDescription(); | 692 identityInfo.GetSecurityDescription(); |
| 697 [securitySummaryField_ | 693 [securitySummaryField_ |
| 698 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; | 694 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; |
| 699 | 695 |
| 700 [securityDetailsField_ | 696 [securityDetailsField_ |
| 701 setStringValue:SysUTF16ToNSString(security_description->details)]; | 697 setStringValue:SysUTF16ToNSString(security_description->details)]; |
| 702 | 698 |
| 703 certificate_ = identityInfo.certificate; | 699 certificate_ = identityInfo.certificate; |
| 704 | 700 |
| 705 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { | 701 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { |
| 706 resetDecisionsField_ = | 702 resetDecisionsField_ = |
| 707 [self addText:base::string16() | 703 [self addText:base::string16() |
| 708 withSize:[NSFont smallSystemFontSize] | 704 withSize:[NSFont smallSystemFontSize] |
| 709 bold:NO | 705 bold:NO |
| 710 toView:securitySectionView_ | 706 toView:securitySectionView_ |
| 711 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)]; | 707 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)]; |
| 712 [resetDecisionsField_ | 708 [resetDecisionsField_ |
| 713 setStringValue:l10n_util::GetNSString( | 709 setStringValue:l10n_util::GetNSString( |
| 714 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)]; | 710 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)]; |
| 715 [self sizeTextFieldHeightToFit:resetDecisionsField_]; | 711 [self sizeTextFieldHeightToFit:resetDecisionsField_]; |
| 716 | 712 |
| 717 resetDecisionsButton_ = | 713 resetDecisionsButton_ = |
| 718 [self addLinkButtonWithText: | 714 [self addLinkButtonWithText: |
| 719 l10n_util::GetNSString( | 715 l10n_util::GetNSString( |
| 720 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON) | 716 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON) |
| 721 toView:securitySectionView_]; | 717 toView:securitySectionView_]; |
| 722 [resetDecisionsButton_ setTarget:self]; | 718 [resetDecisionsButton_ setTarget:self]; |
| 723 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; | 719 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; |
| 724 } | 720 } |
| 725 | 721 |
| 726 [self performLayout]; | 722 [self performLayout]; |
| 727 } | 723 } |
| 728 | 724 |
| 729 // Add a pop-up button for |permissionInfo| to the given view. | 725 // Add a pop-up button for |permissionInfo| to the given view. |
| 730 - (NSPopUpButton*)addPopUpButtonForPermission: | 726 - (NSPopUpButton*)addPopUpButtonForPermission: |
| 731 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 727 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
| 732 toView:(NSView*)view | 728 toView:(NSView*)view |
| 733 atPoint:(NSPoint)point { | 729 atPoint:(NSPoint)point { |
| 734 | |
| 735 GURL url = webContents_ ? webContents_->GetURL() : GURL(); | 730 GURL url = webContents_ ? webContents_->GetURL() : GURL(); |
| 736 __block WebsiteSettingsBubbleController* weakSelf = self; | 731 __block WebsiteSettingsBubbleController* weakSelf = self; |
| 737 PermissionMenuModel::ChangeCallback callback = | 732 PermissionMenuModel::ChangeCallback callback = |
| 738 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { | 733 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { |
| 739 [weakSelf onPermissionChanged:permission.type to:permission.setting]; | 734 [weakSelf onPermissionChanged:permission.type to:permission.setting]; |
| 740 }); | 735 }); |
| 741 base::scoped_nsobject<PermissionSelectorButton> button( | 736 base::scoped_nsobject<PermissionSelectorButton> button( |
| 742 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo | 737 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo |
| 743 forURL:url | 738 forURL:url |
| 744 withCallback:callback | 739 withCallback:callback |
| 745 profile:[self profile]]); | 740 profile:[self profile]]); |
| 746 | 741 |
| 747 // Determine the largest possible size for this button. | 742 // Determine the largest possible size for this button. |
| 748 CGFloat maxTitleWidth = | 743 CGFloat maxTitleWidth = |
| 749 [button maxTitleWidthForContentSettingsType:permissionInfo.type | 744 [button maxTitleWidthForContentSettingsType:permissionInfo.type |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 // Called when the user revokes permission for a previously chosen object. | 791 // Called when the user revokes permission for a previously chosen object. |
| 797 - (void)onChosenObjectDeleted:(const WebsiteSettingsUI::ChosenObjectInfo&)info { | 792 - (void)onChosenObjectDeleted:(const WebsiteSettingsUI::ChosenObjectInfo&)info { |
| 798 if (presenter_) | 793 if (presenter_) |
| 799 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); | 794 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); |
| 800 } | 795 } |
| 801 | 796 |
| 802 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the | 797 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the |
| 803 // last UI element added (either the permission button, in LTR, or the text | 798 // last UI element added (either the permission button, in LTR, or the text |
| 804 // label, in RTL). | 799 // label, in RTL). |
| 805 - (NSPoint)addPermission: | 800 - (NSPoint)addPermission: |
| 806 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo | 801 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo |
| 807 toView:(NSView*)view | 802 toView:(NSView*)view |
| 808 atPoint:(NSPoint)point { | 803 atPoint:(NSPoint)point { |
| 809 base::string16 labelText = | 804 base::string16 labelText = |
| 810 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type); | 805 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type); |
| 811 bool isRTL = base::i18n::IsRTL(); | 806 bool isRTL = base::i18n::IsRTL(); |
| 812 base::scoped_nsobject<NSImage> image( | 807 base::scoped_nsobject<NSImage> image( |
| 813 [WebsiteSettingsUI::GetPermissionIcon(permissionInfo).ToNSImage() | 808 [WebsiteSettingsUI::GetPermissionIcon(permissionInfo) |
| 814 retain]); | 809 .ToNSImage() retain]); |
| 815 | 810 |
| 816 NSPoint position; | 811 NSPoint position; |
| 817 NSImageView* imageView; | 812 NSImageView* imageView; |
| 818 NSPopUpButton* button; | 813 NSPopUpButton* button; |
| 819 NSTextField* label; | 814 NSTextField* label; |
| 820 | 815 |
| 821 CGFloat viewWidth = NSWidth([view frame]); | 816 CGFloat viewWidth = NSWidth([view frame]); |
| 822 | 817 |
| 823 if (isRTL) { | 818 if (isRTL) { |
| 824 point.x = NSWidth([view frame]) - kPermissionImageSize - | 819 point.x = NSWidth([view frame]) - kPermissionImageSize - |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 [self alignPermissionIcon:imageView withTextField:label]; | 985 [self alignPermissionIcon:imageView withTextField:label]; |
| 991 | 986 |
| 992 NSRect buttonFrame = [button frame]; | 987 NSRect buttonFrame = [button frame]; |
| 993 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame)); | 988 return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame)); |
| 994 } | 989 } |
| 995 | 990 |
| 996 // Align an image with a text field by vertically centering the image on | 991 // Align an image with a text field by vertically centering the image on |
| 997 // the cap height of the first line of text. | 992 // the cap height of the first line of text. |
| 998 - (void)alignPermissionIcon:(NSImageView*)imageView | 993 - (void)alignPermissionIcon:(NSImageView*)imageView |
| 999 withTextField:(NSTextField*)textField { | 994 withTextField:(NSTextField*)textField { |
| 1000 | |
| 1001 NSRect frame = [imageView frame]; | 995 NSRect frame = [imageView frame]; |
| 1002 frame.origin.y += kPermissionIconYAdjustment; | 996 frame.origin.y += kPermissionIconYAdjustment; |
| 1003 [imageView setFrame:frame]; | 997 [imageView setFrame:frame]; |
| 1004 } | 998 } |
| 1005 | 999 |
| 1006 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { | 1000 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { |
| 1007 // A result of re-ordering of the permissions (crbug.com/444244) is | 1001 // A result of re-ordering of the permissions (crbug.com/444244) is |
| 1008 // that sometimes permissions may not be displayed at all, so it's | 1002 // that sometimes permissions may not be displayed at all, so it's |
| 1009 // incorrect to check they are set before the cookie info. | 1003 // incorrect to check they are set before the cookie info. |
| 1010 | 1004 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 } | 1091 } |
| 1098 | 1092 |
| 1099 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList | 1093 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList |
| 1100 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { | 1094 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { |
| 1101 [permissionsView_ setSubviews:[NSArray array]]; | 1095 [permissionsView_ setSubviews:[NSArray array]]; |
| 1102 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); | 1096 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); |
| 1103 | 1097 |
| 1104 permissionsPresent_ = YES; | 1098 permissionsPresent_ = YES; |
| 1105 | 1099 |
| 1106 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { | 1100 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { |
| 1107 base::string16 sectionTitle = l10n_util::GetStringUTF16( | 1101 base::string16 sectionTitle = |
| 1108 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); | 1102 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); |
| 1109 | 1103 |
| 1110 for (const auto& permission : permissionInfoList) { | 1104 for (const auto& permission : permissionInfoList) { |
| 1111 controlOrigin.y += kPermissionsVerticalSpacing; | 1105 controlOrigin.y += kPermissionsVerticalSpacing; |
| 1112 NSPoint rowBottomRight = [self addPermission:permission | 1106 NSPoint rowBottomRight = [self addPermission:permission |
| 1113 toView:permissionsView_ | 1107 toView:permissionsView_ |
| 1114 atPoint:controlOrigin]; | 1108 atPoint:controlOrigin]; |
| 1115 controlOrigin.y = rowBottomRight.y; | 1109 controlOrigin.y = rowBottomRight.y; |
| 1116 } | 1110 } |
| 1117 | 1111 |
| 1118 for (auto& object : chosenObjectInfoList) { | 1112 for (auto& object : chosenObjectInfoList) { |
| 1119 controlOrigin.y += kPermissionsVerticalSpacing; | 1113 controlOrigin.y += kPermissionsVerticalSpacing; |
| 1120 NSPoint rowBottomRight = [self addChosenObject:std::move(object) | 1114 NSPoint rowBottomRight = [self addChosenObject:std::move(object) |
| 1121 toView:permissionsView_ | 1115 toView:permissionsView_ |
| 1122 atPoint:controlOrigin]; | 1116 atPoint:controlOrigin]; |
| 1123 controlOrigin.y = rowBottomRight.y; | 1117 controlOrigin.y = rowBottomRight.y; |
| 1124 } | 1118 } |
| 1125 | 1119 |
| 1126 controlOrigin.y += kPermissionsVerticalSpacing; | 1120 controlOrigin.y += kPermissionsVerticalSpacing; |
| 1127 } | 1121 } |
| 1128 | 1122 |
| 1129 [permissionsView_ setFrameSize: | 1123 [permissionsView_ setFrameSize:NSMakeSize(NSWidth([permissionsView_ frame]), |
| 1130 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)]; | 1124 controlOrigin.y)]; |
| 1131 [self performLayout]; | 1125 [self performLayout]; |
| 1132 } | 1126 } |
| 1133 | 1127 |
| 1134 @end | 1128 @end |
| 1135 | 1129 |
| 1136 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( | 1130 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( |
| 1137 content::WebContents* web_contents) | 1131 content::WebContents* web_contents) |
| 1138 : content::WebContentsObserver(web_contents), | 1132 : content::WebContentsObserver(web_contents), |
| 1139 web_contents_(web_contents), | 1133 web_contents_(web_contents), |
| 1140 bubble_controller_(nil) { | 1134 bubble_controller_(nil) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1169 // called each time the location icon is clicked, each click toggles the popup | 1163 // called each time the location icon is clicked, each click toggles the popup |
| 1170 // in and out. | 1164 // in and out. |
| 1171 if (g_is_popup_showing) | 1165 if (g_is_popup_showing) |
| 1172 return; | 1166 return; |
| 1173 | 1167 |
| 1174 // Create the bridge. This will be owned by the bubble controller. | 1168 // Create the bridge. This will be owned by the bubble controller. |
| 1175 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); | 1169 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); |
| 1176 | 1170 |
| 1177 // Create the bubble controller. It will dealloc itself when it closes, | 1171 // Create the bubble controller. It will dealloc itself when it closes, |
| 1178 // resetting |g_is_popup_showing|. | 1172 // resetting |g_is_popup_showing|. |
| 1179 WebsiteSettingsBubbleController* bubble_controller = | 1173 WebsiteSettingsBubbleController* bubble_controller = [ |
| 1180 [[WebsiteSettingsBubbleController alloc] | 1174 [WebsiteSettingsBubbleController alloc] initWithParentWindow:parent |
| 1181 initWithParentWindow:parent | 1175 websiteSettingsUIBridge:bridge |
| 1182 websiteSettingsUIBridge:bridge | 1176 webContents:web_contents |
| 1183 webContents:web_contents | 1177 url:virtual_url]; |
| 1184 url:virtual_url]; | |
| 1185 | 1178 |
| 1186 if (!IsInternalURL(virtual_url)) { | 1179 if (!IsInternalURL(virtual_url)) { |
| 1187 // Initialize the presenter, which holds the model and controls the UI. | 1180 // Initialize the presenter, which holds the model and controls the UI. |
| 1188 // This is also owned by the bubble controller. | 1181 // This is also owned by the bubble controller. |
| 1189 WebsiteSettings* presenter = new WebsiteSettings( | 1182 WebsiteSettings* presenter = new WebsiteSettings( |
| 1190 bridge, profile, | 1183 bridge, profile, |
| 1191 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, | 1184 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, |
| 1192 virtual_url, security_info); | 1185 virtual_url, security_info); |
| 1193 [bubble_controller setPresenter:presenter]; | 1186 [bubble_controller setPresenter:presenter]; |
| 1194 } | 1187 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1212 const CookieInfoList& cookie_info_list) { | 1205 const CookieInfoList& cookie_info_list) { |
| 1213 [bubble_controller_ setCookieInfo:cookie_info_list]; | 1206 [bubble_controller_ setCookieInfo:cookie_info_list]; |
| 1214 } | 1207 } |
| 1215 | 1208 |
| 1216 void WebsiteSettingsUIBridge::SetPermissionInfo( | 1209 void WebsiteSettingsUIBridge::SetPermissionInfo( |
| 1217 const PermissionInfoList& permission_info_list, | 1210 const PermissionInfoList& permission_info_list, |
| 1218 ChosenObjectInfoList chosen_object_info_list) { | 1211 ChosenObjectInfoList chosen_object_info_list) { |
| 1219 [bubble_controller_ setPermissionInfo:permission_info_list | 1212 [bubble_controller_ setPermissionInfo:permission_info_list |
| 1220 andChosenObjects:std::move(chosen_object_info_list)]; | 1213 andChosenObjects:std::move(chosen_object_info_list)]; |
| 1221 } | 1214 } |
| OLD | NEW |