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

Side by Side Diff: chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.mm

Issue 2754383004: Rename WebsiteSettings code to PageInfo. (Closed)
Patch Set: Upload missing comment fix for WebSettingsUI -> PageInfoUI. 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
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/page_info/website_settings_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/page_info/page_info_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
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/mac/bind_objc_block.h" 12 #include "base/mac/bind_objc_block.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #import "chrome/browser/certificate_viewer.h" 15 #import "chrome/browser/certificate_viewer.h"
(...skipping 26 matching lines...) Expand all
42 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 42 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
43 #import "ui/base/cocoa/flipped_view.h" 43 #import "ui/base/cocoa/flipped_view.h"
44 #import "ui/base/cocoa/hover_image_button.h" 44 #import "ui/base/cocoa/hover_image_button.h"
45 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/base/material_design/material_design_controller.h" 46 #include "ui/base/material_design/material_design_controller.h"
47 #include "ui/base/resource/resource_bundle.h" 47 #include "ui/base/resource/resource_bundle.h"
48 #import "ui/gfx/mac/coordinate_conversion.h" 48 #import "ui/gfx/mac/coordinate_conversion.h"
49 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 49 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
50 #include "ui/resources/grit/ui_resources.h" 50 #include "ui/resources/grit/ui_resources.h"
51 51
52 using ChosenObjectInfoPtr = 52 using ChosenObjectInfoPtr = std::unique_ptr<PageInfoUI::ChosenObjectInfo>;
53 std::unique_ptr<WebsiteSettingsUI::ChosenObjectInfo>;
54 using ChosenObjectDeleteCallback = 53 using ChosenObjectDeleteCallback =
55 base::Callback<void(const WebsiteSettingsUI::ChosenObjectInfo&)>; 54 base::Callback<void(const PageInfoUI::ChosenObjectInfo&)>;
56 55
57 namespace { 56 namespace {
58 57
59 // General --------------------------------------------------------------------- 58 // General ---------------------------------------------------------------------
60 59
61 // The default width of the window, in view coordinates. It may be larger to 60 // The default width of the window, in view coordinates. It may be larger to
62 // fit the content. 61 // fit the content.
63 const CGFloat kDefaultWindowWidth = 320; 62 const CGFloat kDefaultWindowWidth = 320;
64 63
65 // Padding around each section 64 // Padding around each section
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Internal Page Bubble -------------------------------------------------------- 105 // Internal Page Bubble --------------------------------------------------------
107 106
108 // Padding between the window frame and content for the internal page bubble. 107 // Padding between the window frame and content for the internal page bubble.
109 const CGFloat kInternalPageFramePadding = 10; 108 const CGFloat kInternalPageFramePadding = 10;
110 109
111 // Spacing between the image and text for internal pages. 110 // Spacing between the image and text for internal pages.
112 const CGFloat kInternalPageImageSpacing = 10; 111 const CGFloat kInternalPageImageSpacing = 10;
113 112
114 // ----------------------------------------------------------------------------- 113 // -----------------------------------------------------------------------------
115 114
116 // NOTE: This assumes that there will never be more than one website settings 115 // NOTE: This assumes that there will never be more than one page info
117 // popup shown, and that the one that is shown is associated with the current 116 // popup shown, and that the one that is shown is associated with the current
118 // window. This matches the behaviour in views: see WebsiteSettingsPopupView. 117 // window. This matches the behaviour in views: see PageInfoPopupView.
119 bool g_is_popup_showing = false; 118 bool g_is_popup_showing = false;
120 119
121 // Takes in the parent window, which should be a BrowserWindow, and gets the 120 // Takes in the parent window, which should be a BrowserWindow, and gets the
122 // proper anchor point for the bubble. The returned point is in screen 121 // proper anchor point for the bubble. The returned point is in screen
123 // coordinates. 122 // coordinates.
124 NSPoint AnchorPointForWindow(NSWindow* parent) { 123 NSPoint AnchorPointForWindow(NSWindow* parent) {
125 BrowserWindowController* controller = [parent windowController]; 124 BrowserWindowController* controller = [parent windowController];
126 NSPoint origin = NSZeroPoint; 125 NSPoint origin = NSZeroPoint;
127 if ([controller isKindOfClass:[BrowserWindowController class]]) { 126 if ([controller isKindOfClass:[BrowserWindowController class]]) {
128 LocationBarViewMac* location_bar = [controller locationBarBridge]; 127 LocationBarViewMac* location_bar = [controller locationBarBridge];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 173 }
175 return self; 174 return self;
176 } 175 }
177 176
178 - (void)deleteClicked:(id)sender { 177 - (void)deleteClicked:(id)sender {
179 callback_.Run(*objectInfo_); 178 callback_.Run(*objectInfo_);
180 } 179 }
181 180
182 @end 181 @end
183 182
184 @implementation WebsiteSettingsBubbleController 183 @implementation PageInfoBubbleController
185 184
186 - (CGFloat)defaultWindowWidth { 185 - (CGFloat)defaultWindowWidth {
187 return kDefaultWindowWidth; 186 return kDefaultWindowWidth;
188 } 187 }
189 188
190 bool IsInternalURL(const GURL& url) { 189 bool IsInternalURL(const GURL& url) {
191 return url.SchemeIs(content::kChromeUIScheme) || 190 return url.SchemeIs(content::kChromeUIScheme) ||
192 url.SchemeIs(content::kChromeDevToolsScheme) || 191 url.SchemeIs(content::kChromeDevToolsScheme) ||
193 url.SchemeIs(extensions::kExtensionScheme) || 192 url.SchemeIs(extensions::kExtensionScheme) ||
194 url.SchemeIs(content::kViewSourceScheme); 193 url.SchemeIs(content::kViewSourceScheme);
195 } 194 }
196 195
197 - (id)initWithParentWindow:(NSWindow*)parentWindow 196 - (id)initWithParentWindow:(NSWindow*)parentWindow
198 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge 197 pageInfoUIBridge:(PageInfoUIBridge*)bridge
199 webContents:(content::WebContents*)webContents 198 webContents:(content::WebContents*)webContents
200 url:(const GURL&)url { 199 url:(const GURL&)url {
201 DCHECK(parentWindow); 200 DCHECK(parentWindow);
202 201
203 webContents_ = webContents; 202 webContents_ = webContents;
204 permissionsPresent_ = NO; 203 permissionsPresent_ = NO;
205 url_ = url; 204 url_ = url;
206 205
207 // Use an arbitrary height; it will be changed in performLayout. 206 // Use an arbitrary height; it will be changed in performLayout.
208 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); 207 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1);
209 // Create an empty window into which content is placed. 208 // Create an empty window into which content is placed.
210 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] 209 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc]
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return Profile::FromBrowserContext(webContents_->GetBrowserContext()); 247 return Profile::FromBrowserContext(webContents_->GetBrowserContext());
249 } 248 }
250 249
251 - (void)windowWillClose:(NSNotification*)notification { 250 - (void)windowWillClose:(NSNotification*)notification {
252 if (presenter_.get()) 251 if (presenter_.get())
253 presenter_->OnUIClosing(); 252 presenter_->OnUIClosing();
254 presenter_.reset(); 253 presenter_.reset();
255 [super windowWillClose:notification]; 254 [super windowWillClose:notification];
256 } 255 }
257 256
258 - (void)setPresenter:(WebsiteSettings*)presenter { 257 - (void)setPresenter:(PageInfo*)presenter {
259 presenter_.reset(presenter); 258 presenter_.reset(presenter);
260 } 259 }
261 260
262 // Create the subviews for the bubble for internal Chrome pages. 261 // Create the subviews for the bubble for internal Chrome pages.
263 - (void)initializeContentsForInternalPage:(const GURL&)url { 262 - (void)initializeContentsForInternalPage:(const GURL&)url {
264 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 263 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
265 264
266 int text = IDS_PAGE_INFO_INTERNAL_PAGE; 265 int text = IDS_PAGE_INFO_INTERNAL_PAGE;
267 int icon = IDR_PRODUCT_LOGO_16; 266 int icon = IDR_PRODUCT_LOGO_16;
268 if (url.SchemeIs(extensions::kExtensionScheme)) { 267 if (url.SchemeIs(extensions::kExtensionScheme)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 [imageView setFrame:imageFrame]; 303 [imageView setFrame:imageFrame];
305 304
306 // Adjust the contentView to fit everything. 305 // Adjust the contentView to fit everything.
307 CGFloat maxY = std::max(NSMaxY(imageFrame), NSMaxY(textFrame)); 306 CGFloat maxY = std::max(NSMaxY(imageFrame), NSMaxY(textFrame));
308 [contentView_ setFrame:NSMakeRect(0, 0, [self defaultWindowWidth], 307 [contentView_ setFrame:NSMakeRect(0, 0, [self defaultWindowWidth],
309 maxY + kInternalPageFramePadding)]; 308 maxY + kInternalPageFramePadding)];
310 309
311 [self sizeAndPositionWindow]; 310 [self sizeAndPositionWindow];
312 } 311 }
313 312
314 // Create the subviews for the website settings bubble. 313 // Create the subviews for the page info bubble.
315 - (void)initializeContents { 314 - (void)initializeContents {
316 securitySectionView_ = [self addSecuritySectionToView:contentView_]; 315 securitySectionView_ = [self addSecuritySectionToView:contentView_];
317 separatorAfterSecuritySection_ = [self addSeparatorToView:contentView_]; 316 separatorAfterSecuritySection_ = [self addSeparatorToView:contentView_];
318 siteSettingsSectionView_ = [self addSiteSettingsSectionToView:contentView_]; 317 siteSettingsSectionView_ = [self addSiteSettingsSectionToView:contentView_];
319 318
320 [self performLayout]; 319 [self performLayout];
321 } 320 }
322 321
323 // Create and return a subview for the security section and add it to the given 322 // Create and return a subview for the security section and add it to the given
324 // |superview|. |superview| retains the new view. 323 // |superview|. |superview| retains the new view.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 [siteSettingsButton_ setTarget:self]; 385 [siteSettingsButton_ setTarget:self];
387 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)]; 386 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)];
388 387
389 return siteSettingsSectionView.get(); 388 return siteSettingsSectionView.get();
390 } 389 }
391 390
392 // Handler for the link button below the list of cookies. 391 // Handler for the link button below the list of cookies.
393 - (void)showCookiesAndSiteData:(id)sender { 392 - (void)showCookiesAndSiteData:(id)sender {
394 DCHECK(webContents_); 393 DCHECK(webContents_);
395 DCHECK(presenter_); 394 DCHECK(presenter_);
396 presenter_->RecordWebsiteSettingsAction( 395 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED);
397 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED);
398 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies(); 396 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies();
399 } 397 }
400 398
401 // Handler for the site settings button below the list of permissions. 399 // Handler for the site settings button below the list of permissions.
402 - (void)showSiteSettingsData:(id)sender { 400 - (void)showSiteSettingsData:(id)sender {
403 DCHECK(webContents_); 401 DCHECK(webContents_);
404 DCHECK(presenter_); 402 DCHECK(presenter_);
405 presenter_->RecordWebsiteSettingsAction( 403 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED);
406 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
407 webContents_->OpenURL(content::OpenURLParams( 404 webContents_->OpenURL(content::OpenURLParams(
408 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), 405 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
409 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 406 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
410 false)); 407 false));
411 } 408 }
412 409
413 // TODO(lgarron): Move some of this to the presenter for separation of concerns 410 // TODO(lgarron): Move some of this to the presenter for separation of concerns
414 // and platform unification. (https://crbug.com/571533) 411 // and platform unification. (https://crbug.com/571533)
415 - (void)openConnectionHelp:(id)sender { 412 - (void)openConnectionHelp:(id)sender {
416 DCHECK(webContents_); 413 DCHECK(webContents_);
417 DCHECK(presenter_); 414 DCHECK(presenter_);
418 presenter_->RecordWebsiteSettingsAction( 415 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED);
419 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED);
420 webContents_->OpenURL(content::OpenURLParams( 416 webContents_->OpenURL(content::OpenURLParams(
421 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), 417 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
422 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 418 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
423 false)); 419 false));
424 } 420 }
425 421
426 // Handler for the link button to show certificate information. 422 // Handler for the link button to show certificate information.
427 - (void)showCertificateInfo:(id)sender { 423 - (void)showCertificateInfo:(id)sender {
428 DCHECK(certificate_.get()); 424 DCHECK(certificate_.get());
429 DCHECK(presenter_); 425 DCHECK(presenter_);
430 presenter_->RecordWebsiteSettingsAction( 426 presenter_->RecordPageInfoAction(
431 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); 427 PageInfo::PAGE_INFO_CERTIFICATE_DIALOG_OPENED);
432 ShowCertificateViewer(webContents_, [self parentWindow], certificate_.get()); 428 ShowCertificateViewer(webContents_, [self parentWindow], certificate_.get());
433 } 429 }
434 430
435 // Handler for the link button to revoke user certificate decisions. 431 // Handler for the link button to revoke user certificate decisions.
436 - (void)resetCertificateDecisions:(id)sender { 432 - (void)resetCertificateDecisions:(id)sender {
437 DCHECK(resetDecisionsButton_); 433 DCHECK(resetDecisionsButton_);
438 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 434 presenter_->OnRevokeSSLErrorBypassButtonPressed();
439 [self close]; 435 [self close];
440 } 436 }
441 437
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 676
681 [button setFrame:buttonFrame]; 677 [button setFrame:buttonFrame];
682 [button setButtonType:NSMomentaryPushInButton]; 678 [button setButtonType:NSMomentaryPushInButton];
683 [button setBezelStyle:NSRegularSquareBezelStyle]; 679 [button setBezelStyle:NSRegularSquareBezelStyle];
684 [view addSubview:button.get()]; 680 [view addSubview:button.get()];
685 681
686 return button.get(); 682 return button.get();
687 } 683 }
688 684
689 // Set the content of the identity and identity status fields. 685 // Set the content of the identity and identity status fields.
690 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { 686 - (void)setIdentityInfo:(const PageInfoUI::IdentityInfo&)identityInfo {
691 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = 687 std::unique_ptr<PageInfoUI::SecurityDescription> security_description =
692 identityInfo.GetSecurityDescription(); 688 identityInfo.GetSecurityDescription();
693 [securitySummaryField_ 689 [securitySummaryField_
694 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; 690 setStringValue:base::SysUTF16ToNSString(security_description->summary)];
695 691
696 [securityDetailsField_ 692 [securityDetailsField_
697 setStringValue:SysUTF16ToNSString(security_description->details)]; 693 setStringValue:SysUTF16ToNSString(security_description->details)];
698 694
699 certificate_ = identityInfo.certificate; 695 certificate_ = identityInfo.certificate;
700 696
701 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { 697 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) {
(...skipping 15 matching lines...) Expand all
717 toView:securitySectionView_]; 713 toView:securitySectionView_];
718 [resetDecisionsButton_ setTarget:self]; 714 [resetDecisionsButton_ setTarget:self];
719 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; 715 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)];
720 } 716 }
721 717
722 [self performLayout]; 718 [self performLayout];
723 } 719 }
724 720
725 // Add a pop-up button for |permissionInfo| to the given view. 721 // Add a pop-up button for |permissionInfo| to the given view.
726 - (NSPopUpButton*)addPopUpButtonForPermission: 722 - (NSPopUpButton*)addPopUpButtonForPermission:
727 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo 723 (const PageInfoUI::PermissionInfo&)permissionInfo
728 toView:(NSView*)view 724 toView:(NSView*)view
729 atPoint:(NSPoint)point { 725 atPoint:(NSPoint)point {
730 GURL url = webContents_ ? webContents_->GetURL() : GURL(); 726 GURL url = webContents_ ? webContents_->GetURL() : GURL();
731 __block WebsiteSettingsBubbleController* weakSelf = self; 727 __block PageInfoBubbleController* weakSelf = self;
732 PermissionMenuModel::ChangeCallback callback = 728 PermissionMenuModel::ChangeCallback callback =
733 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { 729 base::BindBlock(^(const PageInfoUI::PermissionInfo& permission) {
734 [weakSelf onPermissionChanged:permission.type to:permission.setting]; 730 [weakSelf onPermissionChanged:permission.type to:permission.setting];
735 }); 731 });
736 base::scoped_nsobject<PermissionSelectorButton> button( 732 base::scoped_nsobject<PermissionSelectorButton> button(
737 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo 733 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo
738 forURL:url 734 forURL:url
739 withCallback:callback 735 withCallback:callback
740 profile:[self profile]]); 736 profile:[self profile]]);
741 737
742 // Determine the largest possible size for this button. 738 // Determine the largest possible size for this button.
743 CGFloat maxTitleWidth = 739 CGFloat maxTitleWidth =
744 [button maxTitleWidthForContentSettingsType:permissionInfo.type 740 [button maxTitleWidthForContentSettingsType:permissionInfo.type
745 withDefaultSetting:permissionInfo.default_setting 741 withDefaultSetting:permissionInfo.default_setting
746 profile:[self profile]]; 742 profile:[self profile]];
747 743
748 // Ensure the containing view is large enough to contain the button with its 744 // Ensure the containing view is large enough to contain the button with its
749 // widest possible title. 745 // widest possible title.
750 NSRect containerFrame = [view frame]; 746 NSRect containerFrame = [view frame];
751 containerFrame.size.width = 747 containerFrame.size.width =
752 std::max(NSWidth(containerFrame), 748 std::max(NSWidth(containerFrame),
753 point.x + maxTitleWidth + kSectionHorizontalPadding); 749 point.x + maxTitleWidth + kSectionHorizontalPadding);
754 [view setFrame:containerFrame]; 750 [view setFrame:containerFrame];
755 [view addSubview:button.get()]; 751 [view addSubview:button.get()];
756 return button.get(); 752 return button.get();
757 } 753 }
758 754
759 // Add a delete button for |objectInfo| to the given view. 755 // Add a delete button for |objectInfo| to the given view.
760 - (NSButton*)addDeleteButtonForChosenObject:(ChosenObjectInfoPtr)objectInfo 756 - (NSButton*)addDeleteButtonForChosenObject:(ChosenObjectInfoPtr)objectInfo
761 toView:(NSView*)view 757 toView:(NSView*)view
762 atPoint:(NSPoint)point { 758 atPoint:(NSPoint)point {
763 __block WebsiteSettingsBubbleController* weakSelf = self; 759 __block PageInfoBubbleController* weakSelf = self;
764 auto callback = 760 auto callback =
765 base::BindBlock(^(const WebsiteSettingsUI::ChosenObjectInfo& objectInfo) { 761 base::BindBlock(^(const PageInfoUI::ChosenObjectInfo& objectInfo) {
766 [weakSelf onChosenObjectDeleted:objectInfo]; 762 [weakSelf onChosenObjectDeleted:objectInfo];
767 }); 763 });
768 base::scoped_nsobject<ChosenObjectDeleteButton> button( 764 base::scoped_nsobject<ChosenObjectDeleteButton> button(
769 [[ChosenObjectDeleteButton alloc] 765 [[ChosenObjectDeleteButton alloc]
770 initWithChosenObject:std::move(objectInfo) 766 initWithChosenObject:std::move(objectInfo)
771 atPoint:point 767 atPoint:point
772 withCallback:callback]); 768 withCallback:callback]);
773 769
774 // Ensure the containing view is large enough to contain the button. 770 // Ensure the containing view is large enough to contain the button.
775 NSRect containerFrame = [view frame]; 771 NSRect containerFrame = [view frame];
776 containerFrame.size.width = 772 containerFrame.size.width =
777 std::max(NSWidth(containerFrame), point.x + kPermissionDeleteImageSize + 773 std::max(NSWidth(containerFrame), point.x + kPermissionDeleteImageSize +
778 kSectionHorizontalPadding); 774 kSectionHorizontalPadding);
779 [view setFrame:containerFrame]; 775 [view setFrame:containerFrame];
780 [view addSubview:button.get()]; 776 [view addSubview:button.get()];
781 return button.get(); 777 return button.get();
782 } 778 }
783 779
784 // Called when the user changes the setting of a permission. 780 // Called when the user changes the setting of a permission.
785 - (void)onPermissionChanged:(ContentSettingsType)permissionType 781 - (void)onPermissionChanged:(ContentSettingsType)permissionType
786 to:(ContentSetting)newSetting { 782 to:(ContentSetting)newSetting {
787 if (presenter_) 783 if (presenter_)
788 presenter_->OnSitePermissionChanged(permissionType, newSetting); 784 presenter_->OnSitePermissionChanged(permissionType, newSetting);
789 } 785 }
790 786
791 // Called when the user revokes permission for a previously chosen object. 787 // Called when the user revokes permission for a previously chosen object.
792 - (void)onChosenObjectDeleted:(const WebsiteSettingsUI::ChosenObjectInfo&)info { 788 - (void)onChosenObjectDeleted:(const PageInfoUI::ChosenObjectInfo&)info {
793 if (presenter_) 789 if (presenter_)
794 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); 790 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
795 } 791 }
796 792
797 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the 793 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the
798 // last UI element added (either the permission button, in LTR, or the text 794 // last UI element added (either the permission button, in LTR, or the text
799 // label, in RTL). 795 // label, in RTL).
800 - (NSPoint)addPermission: 796 - (NSPoint)addPermission:(const PageInfoUI::PermissionInfo&)permissionInfo
801 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
802 toView:(NSView*)view 797 toView:(NSView*)view
803 atPoint:(NSPoint)point { 798 atPoint:(NSPoint)point {
804 base::string16 labelText = 799 base::string16 labelText =
805 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type); 800 PageInfoUI::PermissionTypeToUIString(permissionInfo.type);
806 bool isRTL = base::i18n::IsRTL(); 801 bool isRTL = base::i18n::IsRTL();
807 base::scoped_nsobject<NSImage> image( 802 base::scoped_nsobject<NSImage> image(
808 [WebsiteSettingsUI::GetPermissionIcon(permissionInfo) 803 [PageInfoUI::GetPermissionIcon(permissionInfo).ToNSImage() retain]);
809 .ToNSImage() retain]);
810 804
811 NSPoint position; 805 NSPoint position;
812 NSImageView* imageView; 806 NSImageView* imageView;
813 NSPopUpButton* button; 807 NSPopUpButton* button;
814 NSTextField* label; 808 NSTextField* label;
815 809
816 CGFloat viewWidth = NSWidth([view frame]); 810 CGFloat viewWidth = NSWidth([view frame]);
817 811
818 if (isRTL) { 812 if (isRTL) {
819 point.x = NSWidth([view frame]) - kPermissionImageSize - 813 point.x = NSWidth([view frame]) - kPermissionImageSize -
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 } 905 }
912 906
913 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the 907 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the
914 // last UI element added (either the permission button, in LTR, or the text 908 // last UI element added (either the permission button, in LTR, or the text
915 // label, in RTL). 909 // label, in RTL).
916 - (NSPoint)addChosenObject:(ChosenObjectInfoPtr)objectInfo 910 - (NSPoint)addChosenObject:(ChosenObjectInfoPtr)objectInfo
917 toView:(NSView*)view 911 toView:(NSView*)view
918 atPoint:(NSPoint)point { 912 atPoint:(NSPoint)point {
919 base::string16 labelText = l10n_util::GetStringFUTF16( 913 base::string16 labelText = l10n_util::GetStringFUTF16(
920 objectInfo->ui_info.label_string_id, 914 objectInfo->ui_info.label_string_id,
921 WebsiteSettingsUI::ChosenObjectToUIString(*objectInfo)); 915 PageInfoUI::ChosenObjectToUIString(*objectInfo));
922 bool isRTL = base::i18n::IsRTL(); 916 bool isRTL = base::i18n::IsRTL();
923 base::scoped_nsobject<NSImage> image( 917 base::scoped_nsobject<NSImage> image(
924 [WebsiteSettingsUI::GetChosenObjectIcon(*objectInfo, false) 918 [PageInfoUI::GetChosenObjectIcon(*objectInfo, false).ToNSImage() retain]);
925 .ToNSImage() retain]);
926 919
927 NSPoint position; 920 NSPoint position;
928 NSImageView* imageView; 921 NSImageView* imageView;
929 NSButton* button; 922 NSButton* button;
930 NSTextField* label; 923 NSTextField* label;
931 924
932 CGFloat viewWidth = NSWidth([view frame]); 925 CGFloat viewWidth = NSWidth([view frame]);
933 926
934 if (isRTL) { 927 if (isRTL) {
935 point.x = NSWidth([view frame]) - kPermissionImageSize - 928 point.x = NSWidth([view frame]) - kPermissionImageSize -
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 // incorrect to check they are set before the cookie info. 996 // incorrect to check they are set before the cookie info.
1004 997
1005 // |cookieInfoList| should only ever have 2 items: first- and third-party 998 // |cookieInfoList| should only ever have 2 items: first- and third-party
1006 // cookies. 999 // cookies.
1007 DCHECK_EQ(cookieInfoList.size(), 2u); 1000 DCHECK_EQ(cookieInfoList.size(), 2u);
1008 1001
1009 int totalAllowed = 0; 1002 int totalAllowed = 0;
1010 for (const auto& i : cookieInfoList) { 1003 for (const auto& i : cookieInfoList) {
1011 totalAllowed += i.allowed; 1004 totalAllowed += i.allowed;
1012 } 1005 }
1013 base::string16 label_text = l10n_util::GetPluralStringFUTF16( 1006 base::string16 label_text =
1014 IDS_WEBSITE_SETTINGS_NUM_COOKIES, totalAllowed); 1007 l10n_util::GetPluralStringFUTF16(IDS_PAGE_INFO_NUM_COOKIES, totalAllowed);
1015 1008
1016 base::string16 sectionTitle = 1009 base::string16 sectionTitle =
1017 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA); 1010 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA);
1018 bool isRTL = base::i18n::IsRTL(); 1011 bool isRTL = base::i18n::IsRTL();
1019 1012
1020 [cookiesView_ setSubviews:[NSArray array]]; 1013 [cookiesView_ setSubviews:[NSArray array]];
1021 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 1014 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1022 1015
1023 CGFloat viewWidth = NSWidth([cookiesView_ frame]); 1016 CGFloat viewWidth = NSWidth([cookiesView_ frame]);
1024 1017
1025 // Reset X for the cookie image. 1018 // Reset X for the cookie image.
1026 if (isRTL) { 1019 if (isRTL) {
1027 controlOrigin.x = viewWidth - kPermissionImageSize - 1020 controlOrigin.x = viewWidth - kPermissionImageSize -
1028 kPermissionImageSpacing - kSectionHorizontalPadding; 1021 kPermissionImageSpacing - kSectionHorizontalPadding;
1029 } 1022 }
1030 1023
1031 WebsiteSettingsUI::PermissionInfo info; 1024 PageInfoUI::PermissionInfo info;
1032 info.type = CONTENT_SETTINGS_TYPE_COOKIES; 1025 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
1033 info.setting = CONTENT_SETTING_ALLOW; 1026 info.setting = CONTENT_SETTING_ALLOW;
1034 // info.default_setting, info.source, and info.is_incognito have not been set, 1027 // info.default_setting, info.source, and info.is_incognito have not been set,
1035 // but GetPermissionIcon doesn't use any of those. 1028 // but GetPermissionIcon doesn't use any of those.
1036 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(info).ToNSImage(); 1029 NSImage* image = PageInfoUI::GetPermissionIcon(info).ToNSImage();
1037 NSImageView* imageView = [self addImageWithSize:[image size] 1030 NSImageView* imageView = [self addImageWithSize:[image size]
1038 toView:cookiesView_ 1031 toView:cookiesView_
1039 atPoint:controlOrigin]; 1032 atPoint:controlOrigin];
1040 [imageView setImage:image]; 1033 [imageView setImage:image];
1041 1034
1042 NSButton* cookiesButton = 1035 NSButton* cookiesButton =
1043 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text) 1036 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text)
1044 toView:cookiesView_]; 1037 toView:cookiesView_];
1045 [cookiesButton setTarget:self]; 1038 [cookiesButton setTarget:self];
1046 [cookiesButton setAction:@selector(showCookiesAndSiteData:)]; 1039 [cookiesButton setAction:@selector(showCookiesAndSiteData:)];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1085
1093 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList 1086 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList
1094 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { 1087 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList {
1095 [permissionsView_ setSubviews:[NSArray array]]; 1088 [permissionsView_ setSubviews:[NSArray array]];
1096 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 1089 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1097 1090
1098 permissionsPresent_ = YES; 1091 permissionsPresent_ = YES;
1099 1092
1100 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { 1093 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) {
1101 base::string16 sectionTitle = 1094 base::string16 sectionTitle =
1102 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); 1095 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_PERMISSIONS);
1103 1096
1104 for (const auto& permission : permissionInfoList) { 1097 for (const auto& permission : permissionInfoList) {
1105 controlOrigin.y += kPermissionsVerticalSpacing; 1098 controlOrigin.y += kPermissionsVerticalSpacing;
1106 NSPoint rowBottomRight = [self addPermission:permission 1099 NSPoint rowBottomRight = [self addPermission:permission
1107 toView:permissionsView_ 1100 toView:permissionsView_
1108 atPoint:controlOrigin]; 1101 atPoint:controlOrigin];
1109 controlOrigin.y = rowBottomRight.y; 1102 controlOrigin.y = rowBottomRight.y;
1110 } 1103 }
1111 1104
1112 for (auto& object : chosenObjectInfoList) { 1105 for (auto& object : chosenObjectInfoList) {
1113 controlOrigin.y += kPermissionsVerticalSpacing; 1106 controlOrigin.y += kPermissionsVerticalSpacing;
1114 NSPoint rowBottomRight = [self addChosenObject:std::move(object) 1107 NSPoint rowBottomRight = [self addChosenObject:std::move(object)
1115 toView:permissionsView_ 1108 toView:permissionsView_
1116 atPoint:controlOrigin]; 1109 atPoint:controlOrigin];
1117 controlOrigin.y = rowBottomRight.y; 1110 controlOrigin.y = rowBottomRight.y;
1118 } 1111 }
1119 1112
1120 controlOrigin.y += kPermissionsVerticalSpacing; 1113 controlOrigin.y += kPermissionsVerticalSpacing;
1121 } 1114 }
1122 1115
1123 [permissionsView_ setFrameSize:NSMakeSize(NSWidth([permissionsView_ frame]), 1116 [permissionsView_ setFrameSize:NSMakeSize(NSWidth([permissionsView_ frame]),
1124 controlOrigin.y)]; 1117 controlOrigin.y)];
1125 [self performLayout]; 1118 [self performLayout];
1126 } 1119 }
1127 1120
1128 @end 1121 @end
1129 1122
1130 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( 1123 PageInfoUIBridge::PageInfoUIBridge(content::WebContents* web_contents)
1131 content::WebContents* web_contents)
1132 : content::WebContentsObserver(web_contents), 1124 : content::WebContentsObserver(web_contents),
1133 web_contents_(web_contents), 1125 web_contents_(web_contents),
1134 bubble_controller_(nil) { 1126 bubble_controller_(nil) {
1135 DCHECK(!g_is_popup_showing); 1127 DCHECK(!g_is_popup_showing);
1136 g_is_popup_showing = true; 1128 g_is_popup_showing = true;
1137 } 1129 }
1138 1130
1139 WebsiteSettingsUIBridge::~WebsiteSettingsUIBridge() { 1131 PageInfoUIBridge::~PageInfoUIBridge() {
1140 DCHECK(g_is_popup_showing); 1132 DCHECK(g_is_popup_showing);
1141 g_is_popup_showing = false; 1133 g_is_popup_showing = false;
1142 } 1134 }
1143 1135
1144 void WebsiteSettingsUIBridge::set_bubble_controller( 1136 void PageInfoUIBridge::set_bubble_controller(
1145 WebsiteSettingsBubbleController* controller) { 1137 PageInfoBubbleController* controller) {
1146 bubble_controller_ = controller; 1138 bubble_controller_ = controller;
1147 } 1139 }
1148 1140
1149 void WebsiteSettingsUIBridge::Show( 1141 void PageInfoUIBridge::Show(gfx::NativeWindow parent,
1150 gfx::NativeWindow parent, 1142 Profile* profile,
1151 Profile* profile, 1143 content::WebContents* web_contents,
1152 content::WebContents* web_contents, 1144 const GURL& virtual_url,
1153 const GURL& virtual_url, 1145 const security_state::SecurityInfo& security_info) {
1154 const security_state::SecurityInfo& security_info) {
1155 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 1146 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
1156 chrome::ShowWebsiteSettingsBubbleViewsAtPoint( 1147 chrome::ShowPageInfoBubbleViewsAtPoint(
1157 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, 1148 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile,
1158 web_contents, virtual_url, security_info); 1149 web_contents, virtual_url, security_info);
1159 return; 1150 return;
1160 } 1151 }
1161 1152
1162 // Don't show the popup if it's already being shown. Since this method is 1153 // Don't show the popup if it's already being shown. Since this method is
1163 // called each time the location icon is clicked, each click toggles the popup 1154 // called each time the location icon is clicked, each click toggles the popup
1164 // in and out. 1155 // in and out.
1165 if (g_is_popup_showing) 1156 if (g_is_popup_showing)
1166 return; 1157 return;
1167 1158
1168 // Create the bridge. This will be owned by the bubble controller. 1159 // Create the bridge. This will be owned by the bubble controller.
1169 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); 1160 PageInfoUIBridge* bridge = new PageInfoUIBridge(web_contents);
1170 1161
1171 // Create the bubble controller. It will dealloc itself when it closes, 1162 // Create the bubble controller. It will dealloc itself when it closes,
1172 // resetting |g_is_popup_showing|. 1163 // resetting |g_is_popup_showing|.
1173 WebsiteSettingsBubbleController* bubble_controller = [ 1164 PageInfoBubbleController* bubble_controller =
1174 [WebsiteSettingsBubbleController alloc] initWithParentWindow:parent 1165 [[PageInfoBubbleController alloc] initWithParentWindow:parent
1175 websiteSettingsUIBridge:bridge 1166 pageInfoUIBridge:bridge
1176 webContents:web_contents 1167 webContents:web_contents
1177 url:virtual_url]; 1168 url:virtual_url];
1178 1169
1179 if (!IsInternalURL(virtual_url)) { 1170 if (!IsInternalURL(virtual_url)) {
1180 // Initialize the presenter, which holds the model and controls the UI. 1171 // Initialize the presenter, which holds the model and controls the UI.
1181 // This is also owned by the bubble controller. 1172 // This is also owned by the bubble controller.
1182 WebsiteSettings* presenter = new WebsiteSettings( 1173 PageInfo* presenter =
1183 bridge, profile, 1174 new PageInfo(bridge, profile,
1184 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, 1175 TabSpecificContentSettings::FromWebContents(web_contents),
1185 virtual_url, security_info); 1176 web_contents, virtual_url, security_info);
1186 [bubble_controller setPresenter:presenter]; 1177 [bubble_controller setPresenter:presenter];
1187 } 1178 }
1188 1179
1189 [bubble_controller showWindow:nil]; 1180 [bubble_controller showWindow:nil];
1190 } 1181 }
1191 1182
1192 void WebsiteSettingsUIBridge::SetIdentityInfo( 1183 void PageInfoUIBridge::SetIdentityInfo(
1193 const WebsiteSettingsUI::IdentityInfo& identity_info) { 1184 const PageInfoUI::IdentityInfo& identity_info) {
1194 [bubble_controller_ setIdentityInfo:identity_info]; 1185 [bubble_controller_ setIdentityInfo:identity_info];
1195 } 1186 }
1196 1187
1197 void WebsiteSettingsUIBridge::RenderFrameDeleted( 1188 void PageInfoUIBridge::RenderFrameDeleted(
1198 content::RenderFrameHost* render_frame_host) { 1189 content::RenderFrameHost* render_frame_host) {
1199 if (render_frame_host == web_contents_->GetMainFrame()) { 1190 if (render_frame_host == web_contents_->GetMainFrame()) {
1200 [bubble_controller_ close]; 1191 [bubble_controller_ close];
1201 } 1192 }
1202 } 1193 }
1203 1194
1204 void WebsiteSettingsUIBridge::SetCookieInfo( 1195 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) {
1205 const CookieInfoList& cookie_info_list) {
1206 [bubble_controller_ setCookieInfo:cookie_info_list]; 1196 [bubble_controller_ setCookieInfo:cookie_info_list];
1207 } 1197 }
1208 1198
1209 void WebsiteSettingsUIBridge::SetPermissionInfo( 1199 void PageInfoUIBridge::SetPermissionInfo(
1210 const PermissionInfoList& permission_info_list, 1200 const PermissionInfoList& permission_info_list,
1211 ChosenObjectInfoList chosen_object_info_list) { 1201 ChosenObjectInfoList chosen_object_info_list) {
1212 [bubble_controller_ setPermissionInfo:permission_info_list 1202 [bubble_controller_ setPermissionInfo:permission_info_list
1213 andChosenObjects:std::move(chosen_object_info_list)]; 1203 andChosenObjects:std::move(chosen_object_info_list)];
1214 } 1204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698