OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 83 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
84 title:(NSString*)title | 84 title:(NSString*)title |
85 icon:(NSImage*)icon | 85 icon:(NSImage*)icon |
86 referenceFrame:(NSRect)referenceFrame; | 86 referenceFrame:(NSRect)referenceFrame; |
87 - (void)initializeBlockedPluginsList; | 87 - (void)initializeBlockedPluginsList; |
88 - (void)initializeTitle; | 88 - (void)initializeTitle; |
89 - (void)initializeRadioGroup; | 89 - (void)initializeRadioGroup; |
90 - (void)initializePopupList; | 90 - (void)initializePopupList; |
91 - (void)initializeGeoLists; | 91 - (void)initializeGeoLists; |
92 - (void)sizeToFitLoadButton; | 92 - (void)sizeToFitLoadButton; |
93 - (void)sizeToFitManageDoneButtons; | 93 - (void)initManageDoneButtons; |
94 - (void)removeInfoButton; | 94 - (void)removeInfoButton; |
95 - (void)popupLinkClicked:(id)sender; | 95 - (void)popupLinkClicked:(id)sender; |
96 - (void)clearGeolocationForCurrentHost:(id)sender; | 96 - (void)clearGeolocationForCurrentHost:(id)sender; |
97 @end | 97 @end |
98 | 98 |
99 @implementation ContentSettingBubbleController | 99 @implementation ContentSettingBubbleController |
100 | 100 |
101 + (ContentSettingBubbleController*) | 101 + (ContentSettingBubbleController*) |
102 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | 102 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
103 parentWindow:(NSWindow*)parentWindow | 103 parentWindow:(NSWindow*)parentWindow |
(...skipping 11 matching lines...) Expand all Loading... |
115 // This method takes ownership of |contentSettingBubbleModel| in all cases. | 115 // This method takes ownership of |contentSettingBubbleModel| in all cases. |
116 scoped_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); | 116 scoped_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); |
117 DCHECK(model.get()); | 117 DCHECK(model.get()); |
118 | 118 |
119 ContentSettingsType settingsType = model->content_type(); | 119 ContentSettingsType settingsType = model->content_type(); |
120 NSString* nibPath = @""; | 120 NSString* nibPath = @""; |
121 switch (settingsType) { | 121 switch (settingsType) { |
122 case CONTENT_SETTINGS_TYPE_COOKIES: | 122 case CONTENT_SETTINGS_TYPE_COOKIES: |
123 nibPath = @"ContentBlockedCookies"; break; | 123 nibPath = @"ContentBlockedCookies"; break; |
124 case CONTENT_SETTINGS_TYPE_IMAGES: | 124 case CONTENT_SETTINGS_TYPE_IMAGES: |
125 nibPath = @"ContentBlockedImages"; break; | |
126 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: | 125 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: |
127 nibPath = @"ContentBlockedJavaScript"; break; | 126 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: |
| 127 nibPath = @"ContentBlockedSimple"; break; |
128 case CONTENT_SETTINGS_TYPE_PLUGINS: | 128 case CONTENT_SETTINGS_TYPE_PLUGINS: |
129 nibPath = @"ContentBlockedPlugins"; break; | 129 nibPath = @"ContentBlockedPlugins"; break; |
130 case CONTENT_SETTINGS_TYPE_POPUPS: | 130 case CONTENT_SETTINGS_TYPE_POPUPS: |
131 nibPath = @"ContentBlockedPopups"; break; | 131 nibPath = @"ContentBlockedPopups"; break; |
132 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 132 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
133 nibPath = @"ContentBlockedGeolocation"; break; | 133 nibPath = @"ContentBlockedGeolocation"; break; |
134 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: | 134 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: |
135 nibPath = @"ContentBlockedMixedScript"; break; | 135 nibPath = @"ContentBlockedMixedScript"; break; |
136 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: | 136 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
137 nibPath = @"ContentProtocolHandlers"; break; | 137 nibPath = @"ContentProtocolHandlers"; break; |
138 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 138 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
139 nibPath = @"ContentBlockedMedia"; break; | 139 nibPath = @"ContentBlockedMedia"; break; |
140 // These content types have no bubble: | 140 // These content types have no bubble: |
141 case CONTENT_SETTINGS_TYPE_DEFAULT: | 141 case CONTENT_SETTINGS_TYPE_DEFAULT: |
142 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 142 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
143 case CONTENT_SETTINGS_TYPE_INTENTS: | 143 case CONTENT_SETTINGS_TYPE_INTENTS: |
144 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: | 144 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: |
145 case CONTENT_SETTINGS_TYPE_FULLSCREEN: | 145 case CONTENT_SETTINGS_TYPE_FULLSCREEN: |
146 case CONTENT_SETTINGS_TYPE_MOUSELOCK: | 146 case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
147 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | 147 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
148 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 148 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
149 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: | |
150 case CONTENT_SETTINGS_NUM_TYPES: | 149 case CONTENT_SETTINGS_NUM_TYPES: |
151 NOTREACHED(); | 150 NOTREACHED(); |
152 } | 151 } |
153 if ((self = [super initWithWindowNibPath:nibPath | 152 if ((self = [super initWithWindowNibPath:nibPath |
154 parentWindow:parentWindow | 153 parentWindow:parentWindow |
155 anchoredAt:anchoredAt])) { | 154 anchoredAt:anchoredAt])) { |
156 contentSettingBubbleModel_.reset(model.release()); | 155 contentSettingBubbleModel_.reset(model.release()); |
157 [self showWindow:nil]; | 156 [self showWindow:nil]; |
158 } | 157 } |
159 return self; | 158 return self; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 // Resize horizontally to fit button if necessary. | 409 // Resize horizontally to fit button if necessary. |
411 NSRect windowFrame = [[self window] frame]; | 410 NSRect windowFrame = [[self window] frame]; |
412 int widthNeeded = NSWidth([loadButton_ frame]) + | 411 int widthNeeded = NSWidth([loadButton_ frame]) + |
413 2 * NSMinX([loadButton_ frame]); | 412 2 * NSMinX([loadButton_ frame]); |
414 if (NSWidth(windowFrame) < widthNeeded) { | 413 if (NSWidth(windowFrame) < widthNeeded) { |
415 windowFrame.size.width = widthNeeded; | 414 windowFrame.size.width = widthNeeded; |
416 [[self window] setFrame:windowFrame display:NO]; | 415 [[self window] setFrame:windowFrame display:NO]; |
417 } | 416 } |
418 } | 417 } |
419 | 418 |
420 - (void)sizeToFitManageDoneButtons { | 419 - (void)initManageDoneButtons { |
| 420 const ContentSettingBubbleModel::BubbleContent& content = |
| 421 contentSettingBubbleModel_->bubble_content(); |
| 422 [manageButton_ setTitle:base::SysUTF8ToNSString(content.manage_link)]; |
| 423 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageButton_]; |
| 424 |
421 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); | 425 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); |
422 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + | 426 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + |
423 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); | 427 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); |
424 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) | 428 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) |
425 return; | 429 return; |
426 | 430 |
427 // Resize window, autoresizing takes care of the rest. | 431 // Resize window, autoresizing takes care of the rest. |
428 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); | 432 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); |
429 size = [[[self window] contentView] convertSize:size toView:nil]; | 433 size = [[[self window] contentView] convertSize:size toView:nil]; |
430 NSRect frame = [[self window] frame]; | 434 NSRect frame = [[self window] frame]; |
431 frame.origin.x -= size.width; | 435 frame.origin.x -= size.width; |
432 frame.size.width += size.width; | 436 frame.size.width += size.width; |
433 [[self window] setFrame:frame display:NO]; | 437 [[self window] setFrame:frame display:NO]; |
434 } | 438 } |
435 | 439 |
436 - (void)awakeFromNib { | 440 - (void)awakeFromNib { |
437 [super awakeFromNib]; | 441 [super awakeFromNib]; |
438 | 442 |
439 [[self bubble] setArrowLocation:info_bubble::kTopRight]; | 443 [[self bubble] setArrowLocation:info_bubble::kTopRight]; |
440 | 444 |
441 // Adapt window size to bottom buttons. Do this before all other layouting. | 445 // Adapt window size to bottom buttons. Do this before all other layouting. |
442 [self sizeToFitManageDoneButtons]; | 446 [self initManageDoneButtons]; |
443 | 447 |
444 [self initializeTitle]; | 448 [self initializeTitle]; |
445 | 449 |
446 ContentSettingsType type = contentSettingBubbleModel_->content_type(); | 450 ContentSettingsType type = contentSettingBubbleModel_->content_type(); |
447 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 451 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
448 [self sizeToFitLoadButton]; | 452 [self sizeToFitLoadButton]; |
449 [self initializeBlockedPluginsList]; | 453 [self initializeBlockedPluginsList]; |
450 } | 454 } |
451 | 455 |
452 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 456 if (allowBlockRadioGroup_) // not bound in cookie bubble xib |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 - (IBAction)manageBlocking:(id)sender { | 498 - (IBAction)manageBlocking:(id)sender { |
495 contentSettingBubbleModel_->OnManageLinkClicked(); | 499 contentSettingBubbleModel_->OnManageLinkClicked(); |
496 } | 500 } |
497 | 501 |
498 - (IBAction)closeBubble:(id)sender { | 502 - (IBAction)closeBubble:(id)sender { |
499 contentSettingBubbleModel_->OnDoneClicked(); | 503 contentSettingBubbleModel_->OnDoneClicked(); |
500 [self close]; | 504 [self close]; |
501 } | 505 } |
502 | 506 |
503 @end // ContentSettingBubbleController | 507 @end // ContentSettingBubbleController |
OLD | NEW |