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

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: 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 website settings
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 117 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(
397 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED); 396 PageInfo::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED);
398 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies(); 397 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies();
399 } 398 }
400 399
401 // Handler for the site settings button below the list of permissions. 400 // Handler for the site settings button below the list of permissions.
402 - (void)showSiteSettingsData:(id)sender { 401 - (void)showSiteSettingsData:(id)sender {
403 DCHECK(webContents_); 402 DCHECK(webContents_);
404 DCHECK(presenter_); 403 DCHECK(presenter_);
405 presenter_->RecordWebsiteSettingsAction( 404 presenter_->RecordPageInfoAction(
406 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED); 405 PageInfo::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
407 webContents_->OpenURL(content::OpenURLParams( 406 webContents_->OpenURL(content::OpenURLParams(
408 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), 407 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
409 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 408 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
410 false)); 409 false));
411 } 410 }
412 411
413 // TODO(lgarron): Move some of this to the presenter for separation of concerns 412 // TODO(lgarron): Move some of this to the presenter for separation of concerns
414 // and platform unification. (https://crbug.com/571533) 413 // and platform unification. (https://crbug.com/571533)
415 - (void)openConnectionHelp:(id)sender { 414 - (void)openConnectionHelp:(id)sender {
416 DCHECK(webContents_); 415 DCHECK(webContents_);
417 DCHECK(presenter_); 416 DCHECK(presenter_);
418 presenter_->RecordWebsiteSettingsAction( 417 presenter_->RecordPageInfoAction(
419 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED); 418 PageInfo::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED);
420 webContents_->OpenURL(content::OpenURLParams( 419 webContents_->OpenURL(content::OpenURLParams(
421 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), 420 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(),
422 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, 421 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
423 false)); 422 false));
424 } 423 }
425 424
426 // Handler for the link button to show certificate information. 425 // Handler for the link button to show certificate information.
427 - (void)showCertificateInfo:(id)sender { 426 - (void)showCertificateInfo:(id)sender {
428 DCHECK(certificate_.get()); 427 DCHECK(certificate_.get());
429 DCHECK(presenter_); 428 DCHECK(presenter_);
430 presenter_->RecordWebsiteSettingsAction( 429 presenter_->RecordPageInfoAction(
431 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); 430 PageInfo::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED);
432 ShowCertificateViewer(webContents_, [self parentWindow], certificate_.get()); 431 ShowCertificateViewer(webContents_, [self parentWindow], certificate_.get());
433 } 432 }
434 433
435 // Handler for the link button to revoke user certificate decisions. 434 // Handler for the link button to revoke user certificate decisions.
436 - (void)resetCertificateDecisions:(id)sender { 435 - (void)resetCertificateDecisions:(id)sender {
437 DCHECK(resetDecisionsButton_); 436 DCHECK(resetDecisionsButton_);
438 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 437 presenter_->OnRevokeSSLErrorBypassButtonPressed();
439 [self close]; 438 [self close];
440 } 439 }
441 440
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 679
681 [button setFrame:buttonFrame]; 680 [button setFrame:buttonFrame];
682 [button setButtonType:NSMomentaryPushInButton]; 681 [button setButtonType:NSMomentaryPushInButton];
683 [button setBezelStyle:NSRegularSquareBezelStyle]; 682 [button setBezelStyle:NSRegularSquareBezelStyle];
684 [view addSubview:button.get()]; 683 [view addSubview:button.get()];
685 684
686 return button.get(); 685 return button.get();
687 } 686 }
688 687
689 // Set the content of the identity and identity status fields. 688 // Set the content of the identity and identity status fields.
690 - (void)setIdentityInfo:(const WebsiteSettingsUI::IdentityInfo&)identityInfo { 689 - (void)setIdentityInfo:(const PageInfoUI::IdentityInfo&)identityInfo {
691 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = 690 std::unique_ptr<PageInfoUI::SecurityDescription> security_description =
692 identityInfo.GetSecurityDescription(); 691 identityInfo.GetSecurityDescription();
693 [securitySummaryField_ 692 [securitySummaryField_
694 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; 693 setStringValue:base::SysUTF16ToNSString(security_description->summary)];
695 694
696 [securityDetailsField_ 695 [securityDetailsField_
697 setStringValue:SysUTF16ToNSString(security_description->details)]; 696 setStringValue:SysUTF16ToNSString(security_description->details)];
698 697
699 certificate_ = identityInfo.certificate; 698 certificate_ = identityInfo.certificate;
700 699
701 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { 700 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) {
(...skipping 15 matching lines...) Expand all
717 toView:securitySectionView_]; 716 toView:securitySectionView_];
718 [resetDecisionsButton_ setTarget:self]; 717 [resetDecisionsButton_ setTarget:self];
719 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; 718 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)];
720 } 719 }
721 720
722 [self performLayout]; 721 [self performLayout];
723 } 722 }
724 723
725 // Add a pop-up button for |permissionInfo| to the given view. 724 // Add a pop-up button for |permissionInfo| to the given view.
726 - (NSPopUpButton*)addPopUpButtonForPermission: 725 - (NSPopUpButton*)addPopUpButtonForPermission:
727 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo 726 (const PageInfoUI::PermissionInfo&)permissionInfo
728 toView:(NSView*)view 727 toView:(NSView*)view
729 atPoint:(NSPoint)point { 728 atPoint:(NSPoint)point {
730 GURL url = webContents_ ? webContents_->GetURL() : GURL(); 729 GURL url = webContents_ ? webContents_->GetURL() : GURL();
731 __block WebsiteSettingsBubbleController* weakSelf = self; 730 __block PageInfoBubbleController* weakSelf = self;
732 PermissionMenuModel::ChangeCallback callback = 731 PermissionMenuModel::ChangeCallback callback =
733 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { 732 base::BindBlock(^(const PageInfoUI::PermissionInfo& permission) {
734 [weakSelf onPermissionChanged:permission.type to:permission.setting]; 733 [weakSelf onPermissionChanged:permission.type to:permission.setting];
735 }); 734 });
736 base::scoped_nsobject<PermissionSelectorButton> button( 735 base::scoped_nsobject<PermissionSelectorButton> button(
737 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo 736 [[PermissionSelectorButton alloc] initWithPermissionInfo:permissionInfo
738 forURL:url 737 forURL:url
739 withCallback:callback 738 withCallback:callback
740 profile:[self profile]]); 739 profile:[self profile]]);
741 740
742 // Determine the largest possible size for this button. 741 // Determine the largest possible size for this button.
743 CGFloat maxTitleWidth = 742 CGFloat maxTitleWidth =
744 [button maxTitleWidthForContentSettingsType:permissionInfo.type 743 [button maxTitleWidthForContentSettingsType:permissionInfo.type
745 withDefaultSetting:permissionInfo.default_setting 744 withDefaultSetting:permissionInfo.default_setting
746 profile:[self profile]]; 745 profile:[self profile]];
747 746
748 // Ensure the containing view is large enough to contain the button with its 747 // Ensure the containing view is large enough to contain the button with its
749 // widest possible title. 748 // widest possible title.
750 NSRect containerFrame = [view frame]; 749 NSRect containerFrame = [view frame];
751 containerFrame.size.width = 750 containerFrame.size.width =
752 std::max(NSWidth(containerFrame), 751 std::max(NSWidth(containerFrame),
753 point.x + maxTitleWidth + kSectionHorizontalPadding); 752 point.x + maxTitleWidth + kSectionHorizontalPadding);
754 [view setFrame:containerFrame]; 753 [view setFrame:containerFrame];
755 [view addSubview:button.get()]; 754 [view addSubview:button.get()];
756 return button.get(); 755 return button.get();
757 } 756 }
758 757
759 // Add a delete button for |objectInfo| to the given view. 758 // Add a delete button for |objectInfo| to the given view.
760 - (NSButton*)addDeleteButtonForChosenObject:(ChosenObjectInfoPtr)objectInfo 759 - (NSButton*)addDeleteButtonForChosenObject:(ChosenObjectInfoPtr)objectInfo
761 toView:(NSView*)view 760 toView:(NSView*)view
762 atPoint:(NSPoint)point { 761 atPoint:(NSPoint)point {
763 __block WebsiteSettingsBubbleController* weakSelf = self; 762 __block PageInfoBubbleController* weakSelf = self;
764 auto callback = 763 auto callback =
765 base::BindBlock(^(const WebsiteSettingsUI::ChosenObjectInfo& objectInfo) { 764 base::BindBlock(^(const PageInfoUI::ChosenObjectInfo& objectInfo) {
766 [weakSelf onChosenObjectDeleted:objectInfo]; 765 [weakSelf onChosenObjectDeleted:objectInfo];
767 }); 766 });
768 base::scoped_nsobject<ChosenObjectDeleteButton> button( 767 base::scoped_nsobject<ChosenObjectDeleteButton> button(
769 [[ChosenObjectDeleteButton alloc] 768 [[ChosenObjectDeleteButton alloc]
770 initWithChosenObject:std::move(objectInfo) 769 initWithChosenObject:std::move(objectInfo)
771 atPoint:point 770 atPoint:point
772 withCallback:callback]); 771 withCallback:callback]);
773 772
774 // Ensure the containing view is large enough to contain the button. 773 // Ensure the containing view is large enough to contain the button.
775 NSRect containerFrame = [view frame]; 774 NSRect containerFrame = [view frame];
776 containerFrame.size.width = 775 containerFrame.size.width =
777 std::max(NSWidth(containerFrame), point.x + kPermissionDeleteImageSize + 776 std::max(NSWidth(containerFrame), point.x + kPermissionDeleteImageSize +
778 kSectionHorizontalPadding); 777 kSectionHorizontalPadding);
779 [view setFrame:containerFrame]; 778 [view setFrame:containerFrame];
780 [view addSubview:button.get()]; 779 [view addSubview:button.get()];
781 return button.get(); 780 return button.get();
782 } 781 }
783 782
784 // Called when the user changes the setting of a permission. 783 // Called when the user changes the setting of a permission.
785 - (void)onPermissionChanged:(ContentSettingsType)permissionType 784 - (void)onPermissionChanged:(ContentSettingsType)permissionType
786 to:(ContentSetting)newSetting { 785 to:(ContentSetting)newSetting {
787 if (presenter_) 786 if (presenter_)
788 presenter_->OnSitePermissionChanged(permissionType, newSetting); 787 presenter_->OnSitePermissionChanged(permissionType, newSetting);
789 } 788 }
790 789
791 // Called when the user revokes permission for a previously chosen object. 790 // Called when the user revokes permission for a previously chosen object.
792 - (void)onChosenObjectDeleted:(const WebsiteSettingsUI::ChosenObjectInfo&)info { 791 - (void)onChosenObjectDeleted:(const PageInfoUI::ChosenObjectInfo&)info {
793 if (presenter_) 792 if (presenter_)
794 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); 793 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
795 } 794 }
796 795
797 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the 796 // 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 797 // last UI element added (either the permission button, in LTR, or the text
799 // label, in RTL). 798 // label, in RTL).
800 - (NSPoint)addPermission: 799 - (NSPoint)addPermission:(const PageInfoUI::PermissionInfo&)permissionInfo
801 (const WebsiteSettingsUI::PermissionInfo&)permissionInfo
802 toView:(NSView*)view 800 toView:(NSView*)view
803 atPoint:(NSPoint)point { 801 atPoint:(NSPoint)point {
804 base::string16 labelText = 802 base::string16 labelText =
805 WebsiteSettingsUI::PermissionTypeToUIString(permissionInfo.type); 803 PageInfoUI::PermissionTypeToUIString(permissionInfo.type);
806 bool isRTL = base::i18n::IsRTL(); 804 bool isRTL = base::i18n::IsRTL();
807 base::scoped_nsobject<NSImage> image( 805 base::scoped_nsobject<NSImage> image(
808 [WebsiteSettingsUI::GetPermissionIcon(permissionInfo) 806 [PageInfoUI::GetPermissionIcon(permissionInfo).ToNSImage() retain]);
809 .ToNSImage() retain]);
810 807
811 NSPoint position; 808 NSPoint position;
812 NSImageView* imageView; 809 NSImageView* imageView;
813 NSPopUpButton* button; 810 NSPopUpButton* button;
814 NSTextField* label; 811 NSTextField* label;
815 812
816 CGFloat viewWidth = NSWidth([view frame]); 813 CGFloat viewWidth = NSWidth([view frame]);
817 814
818 if (isRTL) { 815 if (isRTL) {
819 point.x = NSWidth([view frame]) - kPermissionImageSize - 816 point.x = NSWidth([view frame]) - kPermissionImageSize -
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 } 908 }
912 909
913 // Adds a new row to the UI listing the permissions. Returns the NSPoint of the 910 // 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 911 // last UI element added (either the permission button, in LTR, or the text
915 // label, in RTL). 912 // label, in RTL).
916 - (NSPoint)addChosenObject:(ChosenObjectInfoPtr)objectInfo 913 - (NSPoint)addChosenObject:(ChosenObjectInfoPtr)objectInfo
917 toView:(NSView*)view 914 toView:(NSView*)view
918 atPoint:(NSPoint)point { 915 atPoint:(NSPoint)point {
919 base::string16 labelText = l10n_util::GetStringFUTF16( 916 base::string16 labelText = l10n_util::GetStringFUTF16(
920 objectInfo->ui_info.label_string_id, 917 objectInfo->ui_info.label_string_id,
921 WebsiteSettingsUI::ChosenObjectToUIString(*objectInfo)); 918 PageInfoUI::ChosenObjectToUIString(*objectInfo));
922 bool isRTL = base::i18n::IsRTL(); 919 bool isRTL = base::i18n::IsRTL();
923 base::scoped_nsobject<NSImage> image( 920 base::scoped_nsobject<NSImage> image(
924 [WebsiteSettingsUI::GetChosenObjectIcon(*objectInfo, false) 921 [PageInfoUI::GetChosenObjectIcon(*objectInfo, false).ToNSImage() retain]);
925 .ToNSImage() retain]);
926 922
927 NSPoint position; 923 NSPoint position;
928 NSImageView* imageView; 924 NSImageView* imageView;
929 NSButton* button; 925 NSButton* button;
930 NSTextField* label; 926 NSTextField* label;
931 927
932 CGFloat viewWidth = NSWidth([view frame]); 928 CGFloat viewWidth = NSWidth([view frame]);
933 929
934 if (isRTL) { 930 if (isRTL) {
935 point.x = NSWidth([view frame]) - kPermissionImageSize - 931 point.x = NSWidth([view frame]) - kPermissionImageSize -
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); 1017 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0);
1022 1018
1023 CGFloat viewWidth = NSWidth([cookiesView_ frame]); 1019 CGFloat viewWidth = NSWidth([cookiesView_ frame]);
1024 1020
1025 // Reset X for the cookie image. 1021 // Reset X for the cookie image.
1026 if (isRTL) { 1022 if (isRTL) {
1027 controlOrigin.x = viewWidth - kPermissionImageSize - 1023 controlOrigin.x = viewWidth - kPermissionImageSize -
1028 kPermissionImageSpacing - kSectionHorizontalPadding; 1024 kPermissionImageSpacing - kSectionHorizontalPadding;
1029 } 1025 }
1030 1026
1031 WebsiteSettingsUI::PermissionInfo info; 1027 PageInfoUI::PermissionInfo info;
1032 info.type = CONTENT_SETTINGS_TYPE_COOKIES; 1028 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
1033 info.setting = CONTENT_SETTING_ALLOW; 1029 info.setting = CONTENT_SETTING_ALLOW;
1034 // info.default_setting, info.source, and info.is_incognito have not been set, 1030 // info.default_setting, info.source, and info.is_incognito have not been set,
1035 // but GetPermissionIcon doesn't use any of those. 1031 // but GetPermissionIcon doesn't use any of those.
1036 NSImage* image = WebsiteSettingsUI::GetPermissionIcon(info).ToNSImage(); 1032 NSImage* image = PageInfoUI::GetPermissionIcon(info).ToNSImage();
1037 NSImageView* imageView = [self addImageWithSize:[image size] 1033 NSImageView* imageView = [self addImageWithSize:[image size]
1038 toView:cookiesView_ 1034 toView:cookiesView_
1039 atPoint:controlOrigin]; 1035 atPoint:controlOrigin];
1040 [imageView setImage:image]; 1036 [imageView setImage:image];
1041 1037
1042 NSButton* cookiesButton = 1038 NSButton* cookiesButton =
1043 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text) 1039 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text)
1044 toView:cookiesView_]; 1040 toView:cookiesView_];
1045 [cookiesButton setTarget:self]; 1041 [cookiesButton setTarget:self];
1046 [cookiesButton setAction:@selector(showCookiesAndSiteData:)]; 1042 [cookiesButton setAction:@selector(showCookiesAndSiteData:)];
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 controlOrigin.y += kPermissionsVerticalSpacing; 1116 controlOrigin.y += kPermissionsVerticalSpacing;
1121 } 1117 }
1122 1118
1123 [permissionsView_ setFrameSize:NSMakeSize(NSWidth([permissionsView_ frame]), 1119 [permissionsView_ setFrameSize:NSMakeSize(NSWidth([permissionsView_ frame]),
1124 controlOrigin.y)]; 1120 controlOrigin.y)];
1125 [self performLayout]; 1121 [self performLayout];
1126 } 1122 }
1127 1123
1128 @end 1124 @end
1129 1125
1130 WebsiteSettingsUIBridge::WebsiteSettingsUIBridge( 1126 PageInfoUIBridge::PageInfoUIBridge(content::WebContents* web_contents)
1131 content::WebContents* web_contents)
1132 : content::WebContentsObserver(web_contents), 1127 : content::WebContentsObserver(web_contents),
1133 web_contents_(web_contents), 1128 web_contents_(web_contents),
1134 bubble_controller_(nil) { 1129 bubble_controller_(nil) {
1135 DCHECK(!g_is_popup_showing); 1130 DCHECK(!g_is_popup_showing);
1136 g_is_popup_showing = true; 1131 g_is_popup_showing = true;
1137 } 1132 }
1138 1133
1139 WebsiteSettingsUIBridge::~WebsiteSettingsUIBridge() { 1134 PageInfoUIBridge::~PageInfoUIBridge() {
1140 DCHECK(g_is_popup_showing); 1135 DCHECK(g_is_popup_showing);
1141 g_is_popup_showing = false; 1136 g_is_popup_showing = false;
1142 } 1137 }
1143 1138
1144 void WebsiteSettingsUIBridge::set_bubble_controller( 1139 void PageInfoUIBridge::set_bubble_controller(
1145 WebsiteSettingsBubbleController* controller) { 1140 PageInfoBubbleController* controller) {
1146 bubble_controller_ = controller; 1141 bubble_controller_ = controller;
1147 } 1142 }
1148 1143
1149 void WebsiteSettingsUIBridge::Show( 1144 void PageInfoUIBridge::Show(gfx::NativeWindow parent,
1150 gfx::NativeWindow parent, 1145 Profile* profile,
1151 Profile* profile, 1146 content::WebContents* web_contents,
1152 content::WebContents* web_contents, 1147 const GURL& virtual_url,
1153 const GURL& virtual_url, 1148 const security_state::SecurityInfo& security_info) {
1154 const security_state::SecurityInfo& security_info) {
1155 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 1149 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
1156 chrome::ShowWebsiteSettingsBubbleViewsAtPoint( 1150 chrome::ShowWebsiteSettingsBubbleViewsAtPoint(
1157 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, 1151 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile,
1158 web_contents, virtual_url, security_info); 1152 web_contents, virtual_url, security_info);
1159 return; 1153 return;
1160 } 1154 }
1161 1155
1162 // Don't show the popup if it's already being shown. Since this method is 1156 // 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 1157 // called each time the location icon is clicked, each click toggles the popup
1164 // in and out. 1158 // in and out.
1165 if (g_is_popup_showing) 1159 if (g_is_popup_showing)
1166 return; 1160 return;
1167 1161
1168 // Create the bridge. This will be owned by the bubble controller. 1162 // Create the bridge. This will be owned by the bubble controller.
1169 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); 1163 PageInfoUIBridge* bridge = new PageInfoUIBridge(web_contents);
1170 1164
1171 // Create the bubble controller. It will dealloc itself when it closes, 1165 // Create the bubble controller. It will dealloc itself when it closes,
1172 // resetting |g_is_popup_showing|. 1166 // resetting |g_is_popup_showing|.
1173 WebsiteSettingsBubbleController* bubble_controller = [ 1167 PageInfoBubbleController* bubble_controller =
1174 [WebsiteSettingsBubbleController alloc] initWithParentWindow:parent 1168 [[PageInfoBubbleController alloc] initWithParentWindow:parent
1175 websiteSettingsUIBridge:bridge 1169 PageInfoUIBridge:bridge
1176 webContents:web_contents 1170 webContents:web_contents
1177 url:virtual_url]; 1171 url:virtual_url];
1178 1172
1179 if (!IsInternalURL(virtual_url)) { 1173 if (!IsInternalURL(virtual_url)) {
1180 // Initialize the presenter, which holds the model and controls the UI. 1174 // Initialize the presenter, which holds the model and controls the UI.
1181 // This is also owned by the bubble controller. 1175 // This is also owned by the bubble controller.
1182 WebsiteSettings* presenter = new WebsiteSettings( 1176 PageInfo* presenter =
1183 bridge, profile, 1177 new PageInfo(bridge, profile,
1184 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, 1178 TabSpecificContentSettings::FromWebContents(web_contents),
1185 virtual_url, security_info); 1179 web_contents, virtual_url, security_info);
1186 [bubble_controller setPresenter:presenter]; 1180 [bubble_controller setPresenter:presenter];
1187 } 1181 }
1188 1182
1189 [bubble_controller showWindow:nil]; 1183 [bubble_controller showWindow:nil];
1190 } 1184 }
1191 1185
1192 void WebsiteSettingsUIBridge::SetIdentityInfo( 1186 void PageInfoUIBridge::SetIdentityInfo(
1193 const WebsiteSettingsUI::IdentityInfo& identity_info) { 1187 const PageInfoUI::IdentityInfo& identity_info) {
1194 [bubble_controller_ setIdentityInfo:identity_info]; 1188 [bubble_controller_ setIdentityInfo:identity_info];
1195 } 1189 }
1196 1190
1197 void WebsiteSettingsUIBridge::RenderFrameDeleted( 1191 void PageInfoUIBridge::RenderFrameDeleted(
1198 content::RenderFrameHost* render_frame_host) { 1192 content::RenderFrameHost* render_frame_host) {
1199 if (render_frame_host == web_contents_->GetMainFrame()) { 1193 if (render_frame_host == web_contents_->GetMainFrame()) {
1200 [bubble_controller_ close]; 1194 [bubble_controller_ close];
1201 } 1195 }
1202 } 1196 }
1203 1197
1204 void WebsiteSettingsUIBridge::SetCookieInfo( 1198 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) {
1205 const CookieInfoList& cookie_info_list) {
1206 [bubble_controller_ setCookieInfo:cookie_info_list]; 1199 [bubble_controller_ setCookieInfo:cookie_info_list];
1207 } 1200 }
1208 1201
1209 void WebsiteSettingsUIBridge::SetPermissionInfo( 1202 void PageInfoUIBridge::SetPermissionInfo(
1210 const PermissionInfoList& permission_info_list, 1203 const PermissionInfoList& permission_info_list,
1211 ChosenObjectInfoList chosen_object_info_list) { 1204 ChosenObjectInfoList chosen_object_info_list) {
1212 [bubble_controller_ setPermissionInfo:permission_info_list 1205 [bubble_controller_ setPermissionInfo:permission_info_list
1213 andChosenObjects:std::move(chosen_object_info_list)]; 1206 andChosenObjects:std::move(chosen_object_info_list)];
1214 } 1207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698