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

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

Issue 2712863005: Cocoa Page Info: Implement expanding all permissions (Closed)
Patch Set: Rebase. Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const CGFloat kDefaultWindowWidth = 320; 63 const CGFloat kDefaultWindowWidth = 320;
64 64
65 // Padding around each section 65 // Padding around each section
66 const CGFloat kSectionVerticalPadding = 20; 66 const CGFloat kSectionVerticalPadding = 20;
67 const CGFloat kSectionHorizontalPadding = 16; 67 const CGFloat kSectionHorizontalPadding = 16;
68 68
69 // Links are buttons with invisible padding, so we need to move them back to 69 // Links are buttons with invisible padding, so we need to move them back to
70 // align with other text. 70 // align with other text.
71 const CGFloat kLinkButtonXAdjustment = 1; 71 const CGFloat kLinkButtonXAdjustment = 1;
72 72
73 // Built-in margin for NSButton to take into account.
74 const CGFloat kNSButtonBuiltinMargin = 4;
75
73 // Security Section ------------------------------------------------------------ 76 // Security Section ------------------------------------------------------------
74 77
75 // Spacing between security summary, security details, and cert decisions text. 78 // Spacing between security summary, security details, and cert decisions text.
76 const CGFloat kSecurityParagraphSpacing = 12; 79 const CGFloat kSecurityParagraphSpacing = 12;
77 80
78 // Site Settings Section ------------------------------------------------------- 81 // Site Settings Section -------------------------------------------------------
79 82
80 // Square size of the permission images. 83 // Square size of the permission images.
81 const CGFloat kPermissionImageSize = 16; 84 const CGFloat kPermissionImageSize = 16;
82 85
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 url.SchemeIs(content::kViewSourceScheme); 194 url.SchemeIs(content::kViewSourceScheme);
192 } 195 }
193 196
194 - (id)initWithParentWindow:(NSWindow*)parentWindow 197 - (id)initWithParentWindow:(NSWindow*)parentWindow
195 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge 198 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge
196 webContents:(content::WebContents*)webContents 199 webContents:(content::WebContents*)webContents
197 url:(const GURL&)url { 200 url:(const GURL&)url {
198 DCHECK(parentWindow); 201 DCHECK(parentWindow);
199 202
200 webContents_ = webContents; 203 webContents_ = webContents;
201 permissionsPresent_ = NO;
202 url_ = url; 204 url_ = url;
203 205
204 // Use an arbitrary height; it will be changed in performLayout. 206 // Use an arbitrary height; it will be changed in performLayout.
205 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); 207 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1);
206 // Create an empty window into which content is placed. 208 // Create an empty window into which content is placed.
207 base::scoped_nsobject<InfoBubbleWindow> window( 209 base::scoped_nsobject<InfoBubbleWindow> window(
208 [[InfoBubbleWindow alloc] initWithContentRect:contentRect 210 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
209 styleMask:NSBorderlessWindowMask 211 styleMask:NSBorderlessWindowMask
210 backing:NSBackingStoreBuffered 212 backing:NSBackingStoreBuffered
211 defer:NO]); 213 defer:NO]);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; 371 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease];
370 [cookiesView_ setAutoresizingMask:NSViewWidthSizable]; 372 [cookiesView_ setAutoresizingMask:NSViewWidthSizable];
371 [siteSettingsSectionView addSubview:cookiesView_]; 373 [siteSettingsSectionView addSubview:cookiesView_];
372 374
373 permissionsView_ = 375 permissionsView_ =
374 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; 376 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease];
375 [siteSettingsSectionView addSubview:permissionsView_]; 377 [siteSettingsSectionView addSubview:permissionsView_];
376 378
377 // Create the link button to view site settings. Its position will be set in 379 // Create the link button to view site settings. Its position will be set in
378 // performLayout. 380 // performLayout.
379 NSString* siteSettingsButtonText = 381 NSString* permissionButtonText =
380 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK); 382 l10n_util::GetNSString(IDS_PAGE_INFO_SHOW_ALL_PERMISSIONS_LINK);
381 siteSettingsButton_ = [self addButtonWithText:siteSettingsButtonText 383 permissionButton_ = [self addButtonWithText:permissionButtonText
382 toView:siteSettingsSectionView]; 384 toView:siteSettingsSectionView];
383 [GTMUILocalizerAndLayoutTweaker sizeToFitView:siteSettingsButton_]; 385 [GTMUILocalizerAndLayoutTweaker sizeToFitView:permissionButton_];
384 386
385 [siteSettingsButton_ setTarget:self]; 387 [permissionButton_ setTarget:self];
386 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)]; 388 [permissionButton_ setAction:@selector(showAllPermissions:)];
387 389
388 return siteSettingsSectionView.get(); 390 return siteSettingsSectionView.get();
389 } 391 }
390 392
391 // Handler for the link button below the list of cookies. 393 // Handler for the link button below the list of cookies.
392 - (void)showCookiesAndSiteData:(id)sender { 394 - (void)showCookiesAndSiteData:(id)sender {
393 DCHECK(webContents_); 395 DCHECK(webContents_);
394 DCHECK(presenter_); 396 DCHECK(presenter_);
395 presenter_->RecordWebsiteSettingsAction( 397 presenter_->RecordWebsiteSettingsAction(
396 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED); 398 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED);
397 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies(); 399 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies();
398 } 400 }
399 401
400 // Handler for the site settings button below the list of permissions. 402 // Handler for the site settings button below the list of permissions.
403 - (void)showAllPermissions:(id)sender {
404 DCHECK(presenter_);
405 // TODO(crbug.com/695670): Place this code in a cross-platform location.
406 presenter_->RecordWebsiteSettingsAction(
407 WebsiteSettings::WEBSITE_SETTINGS_SHOW_ALL_PERMISSIONS_PRESSED);
408 // TODO(crbug.com/695723): Avoid hiding a permission when it is changed to the
409 // default.
410 presenter_->PresentAllSitePermissions();
411 }
412
413 // Handler for the site settings button below the list of permissions.
401 - (void)showSiteSettingsData:(id)sender { 414 - (void)showSiteSettingsData:(id)sender {
402 DCHECK(webContents_); 415 DCHECK(webContents_);
403 DCHECK(presenter_); 416 DCHECK(presenter_);
404 presenter_->RecordWebsiteSettingsAction( 417 presenter_->RecordWebsiteSettingsAction(
405 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED); 418 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
406 webContents_->OpenURL(content::OpenURLParams( 419 webContents_->OpenURL(content::OpenURLParams(
407 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), 420 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
408 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 421 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
409 false)); 422 false));
410 } 423 }
(...skipping 23 matching lines...) Expand all
434 // Handler for the link button to revoke user certificate decisions. 447 // Handler for the link button to revoke user certificate decisions.
435 - (void)resetCertificateDecisions:(id)sender { 448 - (void)resetCertificateDecisions:(id)sender {
436 DCHECK(resetDecisionsButton_); 449 DCHECK(resetDecisionsButton_);
437 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 450 presenter_->OnRevokeSSLErrorBypassButtonPressed();
438 [self close]; 451 [self close];
439 } 452 }
440 453
441 - (CGFloat)layoutViewAtRTLStart:(NSView*)view withYPosition:(CGFloat)yPos { 454 - (CGFloat)layoutViewAtRTLStart:(NSView*)view withYPosition:(CGFloat)yPos {
442 CGFloat xPos; 455 CGFloat xPos;
443 if (base::i18n::IsRTL()) { 456 if (base::i18n::IsRTL()) {
444 xPos = 457 xPos = kDefaultWindowWidth - kSectionHorizontalPadding -
445 kDefaultWindowWidth - kSectionHorizontalPadding - NSWidth([view frame]); 458 NSWidth([view frame]) + kNSButtonBuiltinMargin;
446 } else { 459 } else {
447 xPos = kSectionHorizontalPadding; 460 xPos = kSectionHorizontalPadding - kNSButtonBuiltinMargin;
448 } 461 }
449 [view setFrameOrigin:NSMakePoint(xPos, yPos)]; 462 [view setFrameOrigin:NSMakePoint(xPos, yPos - kNSButtonBuiltinMargin)];
450 return yPos + NSHeight([view frame]); 463 return yPos + NSHeight([view frame]) - kNSButtonBuiltinMargin;
451 } 464 }
452 465
453 // Set the Y position of |view| to the given position, and return the position 466 // Set the Y position of |view| to the given position, and return the position
454 // of its bottom edge. 467 // of its bottom edge.
455 - (CGFloat)setYPositionOfView:(NSView*)view to:(CGFloat)position { 468 - (CGFloat)setYPositionOfView:(NSView*)view to:(CGFloat)position {
456 NSRect frame = [view frame]; 469 NSRect frame = [view frame];
457 frame.origin.y = position; 470 frame.origin.y = position;
458 [view setFrame:frame]; 471 [view setFrame:frame];
459 return position + NSHeight(frame); 472 return position + NSHeight(frame);
460 } 473 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 538 }
526 539
527 // Resize the height based on contents. 540 // Resize the height based on contents.
528 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding]; 541 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding];
529 } 542 }
530 543
531 - (void)layoutSiteSettingsSection { 544 - (void)layoutSiteSettingsSection {
532 // Start the layout with the first element. Margins are handled by the caller. 545 // Start the layout with the first element. Margins are handled by the caller.
533 CGFloat yPos = 0; 546 CGFloat yPos = 0;
534 547
535 yPos = 548 yPos += kSectionVerticalPadding;
536 [self setYPositionOfView:cookiesView_ to:yPos + kSectionVerticalPadding]; 549 yPos = [self setYPositionOfView:cookiesView_ to:yPos];
537 550 yPos = [self setYPositionOfView:permissionsView_ to:yPos];
538 if (permissionsPresent_) { 551 yPos = [self layoutViewAtRTLStart:permissionButton_ withYPosition:yPos];
539 // Put the permission info just below the link button.
540 yPos = [self setYPositionOfView:permissionsView_ to:yPos];
541 }
542
543 yPos = [self layoutViewAtRTLStart:siteSettingsButton_ withYPosition:yPos];
544 552
545 // Resize the height based on contents. 553 // Resize the height based on contents.
546 [self setHeightOfView:siteSettingsSectionView_ 554 [self setHeightOfView:siteSettingsSectionView_
547 to:yPos + kSectionVerticalPadding]; 555 to:yPos + kSectionVerticalPadding];
548 } 556 }
549 557
550 // Adjust the size of the window to match the size of the content, and position 558 // Adjust the size of the window to match the size of the content, and position
551 // the bubble anchor appropriately. 559 // the bubble anchor appropriately.
552 - (void)sizeAndPositionWindow { 560 - (void)sizeAndPositionWindow {
553 NSRect windowFrame = [contentView_ frame]; 561 NSRect windowFrame = [contentView_ frame];
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 setFrameSize:NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)]; 1099 setFrameSize:NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)];
1092 1100
1093 [self performLayout]; 1101 [self performLayout];
1094 } 1102 }
1095 1103
1096 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList 1104 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList
1097 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { 1105 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList {
1098 [permissionsView_ setSubviews:[NSArray array]]; 1106 [permissionsView_ setSubviews:[NSArray array]];
1099 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 1107 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1100 1108
1101 permissionsPresent_ = YES; 1109 for (const auto& permission : permissionInfoList) {
1110 controlOrigin.y += kPermissionsVerticalSpacing;
1111 NSPoint rowBottomRight = [self addPermission:permission
1112 toView:permissionsView_
1113 atPoint:controlOrigin];
1114 controlOrigin.y = rowBottomRight.y;
1115 }
1102 1116
1103 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { 1117 for (auto& object : chosenObjectInfoList) {
1104 base::string16 sectionTitle = l10n_util::GetStringUTF16( 1118 controlOrigin.y += kPermissionsVerticalSpacing;
1105 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); 1119 NSPoint rowBottomRight = [self addChosenObject:std::move(object)
1106
1107 for (const auto& permission : permissionInfoList) {
1108 controlOrigin.y += kPermissionsVerticalSpacing;
1109 NSPoint rowBottomRight = [self addPermission:permission
1110 toView:permissionsView_ 1120 toView:permissionsView_
1111 atPoint:controlOrigin]; 1121 atPoint:controlOrigin];
1112 controlOrigin.y = rowBottomRight.y; 1122 controlOrigin.y = rowBottomRight.y;
1113 }
1114
1115 for (auto& object : chosenObjectInfoList) {
1116 controlOrigin.y += kPermissionsVerticalSpacing;
1117 NSPoint rowBottomRight = [self addChosenObject:std::move(object)
1118 toView:permissionsView_
1119 atPoint:controlOrigin];
1120 controlOrigin.y = rowBottomRight.y;
1121 }
1122
1123 controlOrigin.y += kPermissionsVerticalSpacing;
1124 } 1123 }
1125 1124
1125 controlOrigin.y += kPermissionsVerticalSpacing;
1126 [permissionsView_ setFrameSize: 1126 [permissionsView_ setFrameSize:
1127 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)]; 1127 NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)];
1128 [self performLayout]; 1128 [self performLayout];
1129 } 1129 }
1130 1130
1131 - (void)updatePermissionButton:
1132 (WebsiteSettingsUI::VisiblePermissions)visiblePermissions {
1133 base::string16 title = bridge_->GetPermissionButtonString(visiblePermissions);
1134 [permissionButton_ setTitle:base::SysUTF16ToNSString(title)];
1135 if (visiblePermissions == WebsiteSettingsUI::VISIBLE_PERMISSIONS_ALL) {
1136 [permissionButton_ setAction:@selector(showSiteSettingsData:)];
1137 } else {
1138 [permissionButton_ setAction:@selector(showAllPermissions:)];
1139 }
1140 }
1141
1131 @end 1142 @end
1132 1143
1133 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( 1144 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge(
1134 content::WebContents* web_contents) 1145 content::WebContents* web_contents)
1135 : content::WebContentsObserver(web_contents), 1146 : content::WebContentsObserver(web_contents),
1136 web_contents_(web_contents), 1147 web_contents_(web_contents),
1137 bubble_controller_(nil) { 1148 bubble_controller_(nil) {
1138 DCHECK(!g_is_popup_showing); 1149 DCHECK(!g_is_popup_showing);
1139 g_is_popup_showing = true; 1150 g_is_popup_showing = true;
1140 } 1151 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 1223
1213 void WebsiteSettingsUIBridge::SetPermissionInfo( 1224 void WebsiteSettingsUIBridge::SetPermissionInfo(
1214 const PermissionInfoList& permission_info_list, 1225 const PermissionInfoList& permission_info_list,
1215 ChosenObjectInfoList chosen_object_info_list) { 1226 ChosenObjectInfoList chosen_object_info_list) {
1216 [bubble_controller_ setPermissionInfo:permission_info_list 1227 [bubble_controller_ setPermissionInfo:permission_info_list
1217 andChosenObjects:std::move(chosen_object_info_list)]; 1228 andChosenObjects:std::move(chosen_object_info_list)];
1218 } 1229 }
1219 1230
1220 void WebsiteSettingsUIBridge::UpdatePermissionButton( 1231 void WebsiteSettingsUIBridge::UpdatePermissionButton(
1221 WebsiteSettingsUI::VisiblePermissions visible_permissions) { 1232 WebsiteSettingsUI::VisiblePermissions visible_permissions) {
1222 // TODO(crbug.com/657267) 1233 [bubble_controller_ updatePermissionButton:visible_permissions];
1223 } 1234 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698