Chromium Code Reviews| 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; | |
|
Nico
2012/12/14 23:02:26
Do you feel the nib files for the content settings
Bernhard Bauer
2012/12/15 05:44:04
Yes, that probably makes sense. For starters we co
| |
| 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 // These content types have no bubble: | 138 // These content types have no bubble: |
| 139 case CONTENT_SETTINGS_TYPE_DEFAULT: | 139 case CONTENT_SETTINGS_TYPE_DEFAULT: |
| 140 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 140 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 141 case CONTENT_SETTINGS_TYPE_INTENTS: | 141 case CONTENT_SETTINGS_TYPE_INTENTS: |
| 142 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: | 142 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: |
| 143 case CONTENT_SETTINGS_TYPE_FULLSCREEN: | 143 case CONTENT_SETTINGS_TYPE_FULLSCREEN: |
| 144 case CONTENT_SETTINGS_TYPE_MOUSELOCK: | 144 case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
| 145 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 145 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
| 146 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | 146 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| 147 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 147 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 148 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: | |
| 149 case CONTENT_SETTINGS_NUM_TYPES: | 148 case CONTENT_SETTINGS_NUM_TYPES: |
| 150 NOTREACHED(); | 149 NOTREACHED(); |
| 151 } | 150 } |
| 152 if ((self = [super initWithWindowNibPath:nibPath | 151 if ((self = [super initWithWindowNibPath:nibPath |
| 153 parentWindow:parentWindow | 152 parentWindow:parentWindow |
| 154 anchoredAt:anchoredAt])) { | 153 anchoredAt:anchoredAt])) { |
| 155 contentSettingBubbleModel_.reset(model.release()); | 154 contentSettingBubbleModel_.reset(model.release()); |
| 156 [self showWindow:nil]; | 155 [self showWindow:nil]; |
| 157 } | 156 } |
| 158 return self; | 157 return self; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 // Resize horizontally to fit button if necessary. | 408 // Resize horizontally to fit button if necessary. |
| 410 NSRect windowFrame = [[self window] frame]; | 409 NSRect windowFrame = [[self window] frame]; |
| 411 int widthNeeded = NSWidth([loadButton_ frame]) + | 410 int widthNeeded = NSWidth([loadButton_ frame]) + |
| 412 2 * NSMinX([loadButton_ frame]); | 411 2 * NSMinX([loadButton_ frame]); |
| 413 if (NSWidth(windowFrame) < widthNeeded) { | 412 if (NSWidth(windowFrame) < widthNeeded) { |
| 414 windowFrame.size.width = widthNeeded; | 413 windowFrame.size.width = widthNeeded; |
| 415 [[self window] setFrame:windowFrame display:NO]; | 414 [[self window] setFrame:windowFrame display:NO]; |
| 416 } | 415 } |
| 417 } | 416 } |
| 418 | 417 |
| 419 - (void)sizeToFitManageDoneButtons { | 418 - (void)initManageDoneButtons { |
| 419 const ContentSettingBubbleModel::BubbleContent& content = | |
| 420 contentSettingBubbleModel_->bubble_content(); | |
| 421 [manageButton_ setTitle:base::SysUTF8ToNSString(content.manage_link)]; | |
| 422 [GTMUILocalizerAndLayoutTweaker sizeToFitView:manageButton_]; | |
| 423 | |
| 420 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); | 424 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); |
| 421 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + | 425 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + |
| 422 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); | 426 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); |
| 423 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) | 427 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) |
| 424 return; | 428 return; |
| 425 | 429 |
| 426 // Resize window, autoresizing takes care of the rest. | 430 // Resize window, autoresizing takes care of the rest. |
| 427 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); | 431 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); |
| 428 size = [[[self window] contentView] convertSize:size toView:nil]; | 432 size = [[[self window] contentView] convertSize:size toView:nil]; |
| 429 NSRect frame = [[self window] frame]; | 433 NSRect frame = [[self window] frame]; |
| 430 frame.origin.x -= size.width; | 434 frame.origin.x -= size.width; |
| 431 frame.size.width += size.width; | 435 frame.size.width += size.width; |
| 432 [[self window] setFrame:frame display:NO]; | 436 [[self window] setFrame:frame display:NO]; |
| 433 } | 437 } |
| 434 | 438 |
| 435 - (void)awakeFromNib { | 439 - (void)awakeFromNib { |
| 436 [super awakeFromNib]; | 440 [super awakeFromNib]; |
| 437 | 441 |
| 438 [[self bubble] setArrowLocation:info_bubble::kTopRight]; | 442 [[self bubble] setArrowLocation:info_bubble::kTopRight]; |
| 439 | 443 |
| 440 // Adapt window size to bottom buttons. Do this before all other layouting. | 444 // Adapt window size to bottom buttons. Do this before all other layouting. |
| 441 [self sizeToFitManageDoneButtons]; | 445 [self initManageDoneButtons]; |
| 442 | 446 |
| 443 [self initializeTitle]; | 447 [self initializeTitle]; |
| 444 | 448 |
| 445 ContentSettingsType type = contentSettingBubbleModel_->content_type(); | 449 ContentSettingsType type = contentSettingBubbleModel_->content_type(); |
| 446 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 450 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 447 [self sizeToFitLoadButton]; | 451 [self sizeToFitLoadButton]; |
| 448 [self initializeBlockedPluginsList]; | 452 [self initializeBlockedPluginsList]; |
| 449 } | 453 } |
| 450 | 454 |
| 451 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 455 if (allowBlockRadioGroup_) // not bound in cookie bubble xib |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 - (IBAction)manageBlocking:(id)sender { | 497 - (IBAction)manageBlocking:(id)sender { |
| 494 contentSettingBubbleModel_->OnManageLinkClicked(); | 498 contentSettingBubbleModel_->OnManageLinkClicked(); |
| 495 } | 499 } |
| 496 | 500 |
| 497 - (IBAction)closeBubble:(id)sender { | 501 - (IBAction)closeBubble:(id)sender { |
| 498 contentSettingBubbleModel_->OnDoneClicked(); | 502 contentSettingBubbleModel_->OnDoneClicked(); |
| 499 [self close]; | 503 [self close]; |
| 500 } | 504 } |
| 501 | 505 |
| 502 @end // ContentSettingBubbleController | 506 @end // ContentSettingBubbleController |
| OLD | NEW |