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

Side by Side Diff: chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm

Issue 2826233002: [subresource_filter] Mac UI updated and xib replaced with code based layout. (Closed)
Patch Set: csharrison feedback addressed Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/content_settings/content_setting_bubble_cocoa.h " 5 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/plugins/plugin_finder.h" 15 #include "chrome/browser/plugins/plugin_finder.h"
16 #include "chrome/browser/plugins/plugin_metadata.h" 16 #include "chrome/browser/plugins/plugin_metadata.h"
17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
18 #import "chrome/browser/ui/cocoa/l10n_util.h" 18 #import "chrome/browser/ui/cocoa/l10n_util.h"
19 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
20 #import "chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_co ntroller.h"
19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 21 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
20 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" 22 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h"
21 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
22 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
23 #include "components/content_settings/core/browser/host_content_settings_map.h" 24 #include "components/content_settings/core/browser/host_content_settings_map.h"
24 #include "content/public/browser/navigation_handle.h" 25 #include "content/public/browser/navigation_handle.h"
25 #include "content/public/browser/plugin_service.h" 26 #include "content/public/browser/plugin_service.h"
26 #include "content/public/browser/web_contents_observer.h" 27 #include "content/public/browser/web_contents_observer.h"
27 #include "skia/ext/skia_utils_mac.h" 28 #include "skia/ext/skia_utils_mac.h"
28 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 29 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
29 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 30 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 32
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // close up shop. 199 // close up shop.
199 [controller_ closeBubble:nil]; 200 [controller_ closeBubble:nil];
200 } 201 }
201 202
202 private: 203 private:
203 ContentSettingBubbleController* controller_; // weak 204 ContentSettingBubbleController* controller_; // weak
204 205
205 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleWebContentsObserverBridge); 206 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleWebContentsObserverBridge);
206 }; 207 };
207 208
208 @interface ContentSettingBubbleController(Private) 209 @interface ContentSettingBubbleController (Private)
209 - (id)initWithModel:(ContentSettingBubbleModel*)settingsBubbleModel 210 - (id)initWithModel:(ContentSettingBubbleModel*)settingsBubbleModel
210 webContents:(content::WebContents*)webContents 211 webContents:(content::WebContents*)webContents
211 parentWindow:(NSWindow*)parentWindow 212 parentWindow:(NSWindow*)parentWindow
212 decoration:(ContentSettingDecoration*)decoration 213 decoration:(ContentSettingDecoration*)decoration
213 anchoredAt:(NSPoint)anchoredAt; 214 anchoredAt:(NSPoint)anchoredAt;
214 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model; 215 + (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model;
216 + (ContentSettingBubbleController*)allocControllerForModel:
217 (ContentSettingBubbleModel*)model;
215 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame 218 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame
216 title:(NSString*)title 219 title:(NSString*)title
217 icon:(NSImage*)icon 220 icon:(NSImage*)icon
218 referenceFrame:(NSRect)referenceFrame; 221 referenceFrame:(NSRect)referenceFrame;
219 - (void)initializeBlockedPluginsList; 222 - (void)initializeBlockedPluginsList;
220 - (void)initializeTitle; 223 - (void)initializeTitle;
221 - (void)initializeMessage; 224 - (void)initializeMessage;
222 - (void)initializeRadioGroup; 225 - (void)initializeRadioGroup;
223 - (void)initializeItemList; 226 - (void)initializeItemList;
224 - (void)initializeGeoLists; 227 - (void)initializeGeoLists;
225 - (void)initializeMediaMenus; 228 - (void)initializeMediaMenus;
226 - (void)initializeMIDISysExLists; 229 - (void)initializeMIDISysExLists;
227 - (void)sizeToFitLoadButton; 230 - (void)sizeToFitLoadButton;
228 - (void)initManageDoneButtons; 231 - (void)initManageDoneButtons;
229 - (void)removeInfoButton; 232 - (void)removeInfoButton;
230 - (void)popupLinkClicked:(id)sender; 233 - (void)popupLinkClicked:(id)sender;
231 - (void)clearGeolocationForCurrentHost:(id)sender; 234 - (void)clearGeolocationForCurrentHost:(id)sender;
232 - (void)clearMIDISysExForCurrentHost:(id)sender; 235 - (void)clearMIDISysExForCurrentHost:(id)sender;
233 @end 236 @end
234 237
235 @implementation ContentSettingBubbleController 238 @implementation ContentSettingBubbleController
236 239
237 + (ContentSettingBubbleController*) 240 + (ContentSettingBubbleController*)
238 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel 241 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel
239 webContents:(content::WebContents*)webContents 242 webContents:(content::WebContents*)webContents
240 parentWindow:(NSWindow*)parentWindow 243 parentWindow:(NSWindow*)parentWindow
241 decoration:(ContentSettingDecoration*)decoration 244 decoration:(ContentSettingDecoration*)decoration
242 anchoredAt:(NSPoint)anchor { 245 anchoredAt:(NSPoint)anchor {
243 // Autoreleases itself on bubble close. 246 // Autoreleases itself on bubble close.
244 return [[ContentSettingBubbleController alloc] 247 ContentSettingBubbleController* controller =
245 initWithModel:contentSettingBubbleModel 248 [self allocControllerForModel:contentSettingBubbleModel];
246 webContents:webContents 249
247 parentWindow:parentWindow 250 DCHECK(controller);
248 decoration:decoration 251
249 anchoredAt:anchor]; 252 return [controller initWithModel:contentSettingBubbleModel
253 webContents:webContents
254 parentWindow:parentWindow
255 decoration:decoration
256 anchoredAt:anchor];
250 } 257 }
251 258
252 struct ContentTypeToNibPath { 259 struct ContentTypeToNibPath {
253 ContentSettingsType type; 260 ContentSettingsType type;
254 NSString* path; 261 NSString* path;
255 }; 262 };
256 263
257 const ContentTypeToNibPath kNibPaths[] = { 264 const ContentTypeToNibPath kNibPaths[] = {
258 {CONTENT_SETTINGS_TYPE_COOKIES, @"ContentBlockedCookies"}, 265 {CONTENT_SETTINGS_TYPE_COOKIES, @"ContentBlockedCookies"},
259 {CONTENT_SETTINGS_TYPE_IMAGES, @"ContentBlockedSimple"}, 266 {CONTENT_SETTINGS_TYPE_IMAGES, @"ContentBlockedSimple"},
(...skipping 11 matching lines...) Expand all
271 webContents:(content::WebContents*)webContents 278 webContents:(content::WebContents*)webContents
272 parentWindow:(NSWindow*)parentWindow 279 parentWindow:(NSWindow*)parentWindow
273 decoration:(ContentSettingDecoration*)decoration 280 decoration:(ContentSettingDecoration*)decoration
274 anchoredAt:(NSPoint)anchoredAt { 281 anchoredAt:(NSPoint)anchoredAt {
275 // This method takes ownership of |contentSettingBubbleModel| in all cases. 282 // This method takes ownership of |contentSettingBubbleModel| in all cases.
276 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); 283 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel);
277 DCHECK(model.get()); 284 DCHECK(model.get());
278 observerBridge_.reset( 285 observerBridge_.reset(
279 new ContentSettingBubbleWebContentsObserverBridge(webContents, self)); 286 new ContentSettingBubbleWebContentsObserverBridge(webContents, self));
280 287
281 NSString* nibPath = [self getNibPathForModel:model.get()]; 288 NSString* nibPath =
289 [ContentSettingBubbleController getNibPathForModel:model.get()];
282 290
283 DCHECK_NE(0u, [nibPath length]); 291 DCHECK_NE(0u, [nibPath length]);
284 292
285 if ((self = [super initWithWindowNibPath:nibPath 293 if ((self = [super initWithWindowNibPath:nibPath
286 parentWindow:parentWindow 294 parentWindow:parentWindow
287 anchoredAt:anchoredAt])) { 295 anchoredAt:anchoredAt])) {
288 contentSettingBubbleModel_ = std::move(model); 296 contentSettingBubbleModel_ = std::move(model);
289 decoration_ = decoration; 297 decoration_ = decoration;
290 [self showWindow:nil]; 298 [self showWindow:nil];
291 } 299 }
292 return self; 300 return self;
293 } 301 }
294 302
295 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model { 303 - (id)initWithModel:(ContentSettingBubbleModel*)contentSettingBubbleModel
304 webContents:(content::WebContents*)webContents
305 window:(NSWindow*)window
306 parentWindow:(NSWindow*)parentWindow
307 decoration:(ContentSettingDecoration*)decoration
308 anchoredAt:(NSPoint)anchoredAt {
309 // This method takes ownership of |contentSettingBubbleModel| in all cases.
310 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel);
311 DCHECK(model.get());
312 observerBridge_.reset(
313 new ContentSettingBubbleWebContentsObserverBridge(webContents, self));
314
315 contentSettingBubbleModel_ = std::move(model);
316
317 if ((self = [super initWithWindow:window
318 parentWindow:parentWindow
319 anchoredAt:anchoredAt])) {
320 decoration_ = decoration;
321 [self showWindow:nil];
322 }
323 return self;
324 }
325
326 + (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model {
296 NSString* nibPath = @""; 327 NSString* nibPath = @"";
297 328
298 ContentSettingSimpleBubbleModel* simple_bubble = model->AsSimpleBubbleModel(); 329 ContentSettingSimpleBubbleModel* simple_bubble = model->AsSimpleBubbleModel();
299 if (simple_bubble) { 330 if (simple_bubble) {
300 ContentSettingsType settingsType = simple_bubble->content_type(); 331 ContentSettingsType settingsType = simple_bubble->content_type();
301 332
302 for (const ContentTypeToNibPath& type_to_path : kNibPaths) { 333 for (const ContentTypeToNibPath& type_to_path : kNibPaths) {
303 if (settingsType == type_to_path.type) { 334 if (settingsType == type_to_path.type) {
304 nibPath = type_to_path.path; 335 nibPath = type_to_path.path;
305 break; 336 break;
306 } 337 }
307 } 338 }
308 } 339 }
309 340
310 if (model->AsMediaStreamBubbleModel()) 341 if (model->AsMediaStreamBubbleModel())
311 nibPath = @"ContentBlockedMedia"; 342 nibPath = @"ContentBlockedMedia";
312 343
313 if (model->AsSubresourceFilterBubbleModel())
314 nibPath = @"ContentSubresourceFilter";
315
316 if (model->AsDownloadsBubbleModel()) 344 if (model->AsDownloadsBubbleModel())
317 nibPath = @"ContentBlockedDownloads"; 345 nibPath = @"ContentBlockedDownloads";
318 return nibPath; 346 return nibPath;
319 } 347 }
320 348
349 + (ContentSettingBubbleController*)allocControllerForModel:
350 (ContentSettingBubbleModel*)model {
351 // Check if the view is expressed in xib file or not.
352 NSString* nibPath = [self getNibPathForModel:model];
353
354 // Autoreleases itself on bubble close.
355
356 if ([nibPath length] > 0u)
357 return [ContentSettingBubbleController alloc];
358
359 if (model->AsSubresourceFilterBubbleModel())
360 return [SubresourceFilterBubbleController alloc];
361
362 return nil;
363 }
364
321 - (void)initializeTitle { 365 - (void)initializeTitle {
322 if (!titleLabel_) 366 if (!titleLabel_)
323 return; 367 return;
324 368
325 NSString* label = base::SysUTF16ToNSString( 369 NSString* label = base::SysUTF16ToNSString(
326 contentSettingBubbleModel_->bubble_content().title); 370 contentSettingBubbleModel_->bubble_content().title);
327 [titleLabel_ setStringValue:label]; 371 [titleLabel_ setStringValue:label];
328 372
329 // Layout title post-localization. 373 // Layout title post-localization.
330 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker 374 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 NSRect windowFrame = [[self window] frame]; 804 NSRect windowFrame = [[self window] frame];
761 int widthNeeded = NSWidth([loadButton_ frame]) + 805 int widthNeeded = NSWidth([loadButton_ frame]) +
762 2 * NSMinX([loadButton_ frame]); 806 2 * NSMinX([loadButton_ frame]);
763 if (NSWidth(windowFrame) < widthNeeded) { 807 if (NSWidth(windowFrame) < widthNeeded) {
764 windowFrame.size.width = widthNeeded; 808 windowFrame.size.width = widthNeeded;
765 [[self window] setFrame:windowFrame display:NO]; 809 [[self window] setFrame:windowFrame display:NO];
766 } 810 }
767 } 811 }
768 812
769 - (void)initManageDoneButtons { 813 - (void)initManageDoneButtons {
814 if (!manageButton_ && !doneButton_)
815 return;
816
770 const ContentSettingBubbleModel::BubbleContent& content = 817 const ContentSettingBubbleModel::BubbleContent& content =
771 contentSettingBubbleModel_->bubble_content(); 818 contentSettingBubbleModel_->bubble_content();
772 [manageButton_ setTitle:base::SysUTF16ToNSString(content.manage_text)]; 819
773 [GTMUILocalizerAndLayoutTweaker sizeToFitView:[manageButton_ superview]]; 820 CGFloat requiredWidthForManageButton = 0.0;
821 if (manageButton_) {
822 [manageButton_ setTitle:base::SysUTF16ToNSString(content.manage_text)];
823 [GTMUILocalizerAndLayoutTweaker sizeToFitView:[manageButton_ superview]];
824 requiredWidthForManageButton =
825 NSMaxX([manageButton_ frame]) + kManageDonePadding;
826 }
827
828 if (!doneButton_)
829 return;
830
831 NSString* doneLabel = base::SysUTF16ToNSString(content.done_button_text);
832 if ([doneLabel length] > 0u)
833 [doneButton_ setTitle:doneLabel];
774 834
775 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); 835 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]);
776 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + 836 CGFloat requiredWidth = requiredWidthForManageButton +
777 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); 837 NSWidth([[doneButton_ superview] frame]) -
838 NSMinX([doneButton_ frame]);
778 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) 839 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_)
779 return; 840 return;
780 841
781 // Resize window, autoresizing takes care of the rest. 842 // Resize window, autoresizing takes care of the rest.
782 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); 843 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0);
783 size = [[[self window] contentView] convertSize:size toView:nil]; 844 size = [[[self window] contentView] convertSize:size toView:nil];
784 NSRect frame = [[self window] frame]; 845 NSRect frame = [[self window] frame];
785 frame.origin.x -= size.width; 846 frame.origin.x -= size.width;
786 frame.size.width += size.width; 847 frame.size.width += size.width;
787 [[self window] setFrame:frame display:NO]; 848 [[self window] setFrame:frame display:NO];
788 } 849 }
789 850
790 - (void)awakeFromNib { 851 - (void)awakeFromNib {
791 [super awakeFromNib]; 852 [super awakeFromNib];
853 [self layoutView];
854 }
792 855
856 - (void)layoutView {
793 ContentSettingSimpleBubbleModel* simple_bubble = 857 ContentSettingSimpleBubbleModel* simple_bubble =
794 contentSettingBubbleModel_->AsSimpleBubbleModel(); 858 contentSettingBubbleModel_->AsSimpleBubbleModel();
795 859
796 [[self bubble] setArrowLocation:info_bubble::kTopTrailing]; 860 [[self bubble] setArrowLocation:info_bubble::kTopTrailing];
797 861
798 // Adapt window size to bottom buttons. Do this before all other layouting. 862 // Adapt window size to bottom buttons. Do this before all other layouting.
799 if ((simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) || 863 if ((simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) ||
800 contentSettingBubbleModel_->AsDownloadsBubbleModel()) 864 contentSettingBubbleModel_->AsDownloadsBubbleModel() ||
865 contentSettingBubbleModel_->AsSubresourceFilterBubbleModel()) {
801 [self initManageDoneButtons]; 866 [self initManageDoneButtons];
867 }
802 868
803 [self initializeTitle]; 869 [self initializeTitle];
804 [self initializeMessage]; 870 [self initializeMessage];
805 871
806 // Note that the per-content-type methods and |initializeRadioGroup| below 872 // Note that the per-content-type methods and |initializeRadioGroup| below
807 // must be kept in the correct order, as they make interdependent adjustments 873 // must be kept in the correct order, as they make interdependent adjustments
808 // of the bubble's height. 874 // of the bubble's height.
809 if (simple_bubble && 875 if (simple_bubble &&
810 simple_bubble->content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) { 876 simple_bubble->content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) {
811 if (!simple_bubble->bubble_content().custom_link.empty()) 877 if (!simple_bubble->bubble_content().custom_link.empty())
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 982
917 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { 983 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus {
918 return &mediaMenus_; 984 return &mediaMenus_;
919 } 985 }
920 986
921 - (LocationBarDecoration*)decorationForBubble { 987 - (LocationBarDecoration*)decorationForBubble {
922 return decoration_; 988 return decoration_;
923 } 989 }
924 990
925 @end // ContentSettingBubbleController 991 @end // ContentSettingBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698