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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 anchoredAt:(NSPoint)anchoredAt; | 86 anchoredAt:(NSPoint)anchoredAt; | 
| 87 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 87 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 
| 88 title:(NSString*)title | 88 title:(NSString*)title | 
| 89 icon:(NSImage*)icon | 89 icon:(NSImage*)icon | 
| 90 referenceFrame:(NSRect)referenceFrame; | 90 referenceFrame:(NSRect)referenceFrame; | 
| 91 - (void)initializeBlockedPluginsList; | 91 - (void)initializeBlockedPluginsList; | 
| 92 - (void)initializeTitle; | 92 - (void)initializeTitle; | 
| 93 - (void)initializeRadioGroup; | 93 - (void)initializeRadioGroup; | 
| 94 - (void)initializePopupList; | 94 - (void)initializePopupList; | 
| 95 - (void)initializeGeoLists; | 95 - (void)initializeGeoLists; | 
| 96 - (void)initializeProtocolHandlers; | |
| 96 - (void)sizeToFitLoadButton; | 97 - (void)sizeToFitLoadButton; | 
| 97 - (void)sizeToFitManageDoneButtons; | 98 - (void)sizeToFitManageDoneButtons; | 
| 98 - (void)removeInfoButton; | 99 - (void)removeInfoButton; | 
| 99 - (void)popupLinkClicked:(id)sender; | 100 - (void)popupLinkClicked:(id)sender; | 
| 100 - (void)clearGeolocationForCurrentHost:(id)sender; | 101 - (void)clearGeolocationForCurrentHost:(id)sender; | 
| 101 @end | 102 @end | 
| 102 | 103 | 
| 103 @implementation ContentSettingBubbleController | 104 @implementation ContentSettingBubbleController | 
| 104 | 105 | 
| 105 + (ContentSettingBubbleController*) | 106 + (ContentSettingBubbleController*) | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 130 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: | 131 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: | 
| 131 nibPath = @"ContentBlockedJavaScript"; break; | 132 nibPath = @"ContentBlockedJavaScript"; break; | 
| 132 case CONTENT_SETTINGS_TYPE_PLUGINS: | 133 case CONTENT_SETTINGS_TYPE_PLUGINS: | 
| 133 nibPath = @"ContentBlockedPlugins"; break; | 134 nibPath = @"ContentBlockedPlugins"; break; | 
| 134 case CONTENT_SETTINGS_TYPE_POPUPS: | 135 case CONTENT_SETTINGS_TYPE_POPUPS: | 
| 135 nibPath = @"ContentBlockedPopups"; break; | 136 nibPath = @"ContentBlockedPopups"; break; | 
| 136 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 137 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 
| 137 nibPath = @"ContentBlockedGeolocation"; break; | 138 nibPath = @"ContentBlockedGeolocation"; break; | 
| 138 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: | 139 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: | 
| 139 nibPath = @"ContentBlockedMixedScript"; break; | 140 nibPath = @"ContentBlockedMixedScript"; break; | 
| 141 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: | |
| 142 nibPath = @"ContentProtocolHandlers"; break; | |
| 140 default: | 143 default: | 
| 141 NOTREACHED(); | 144 NOTREACHED(); | 
| 142 } | 145 } | 
| 143 if ((self = [super initWithWindowNibPath:nibPath | 146 if ((self = [super initWithWindowNibPath:nibPath | 
| 144 parentWindow:parentWindow | 147 parentWindow:parentWindow | 
| 145 anchoredAt:anchoredAt])) { | 148 anchoredAt:anchoredAt])) { | 
| 146 contentSettingBubbleModel_.reset(model.release()); | 149 contentSettingBubbleModel_.reset(model.release()); | 
| 147 [self showWindow:nil]; | 150 [self showWindow:nil]; | 
| 148 } | 151 } | 
| 149 return self; | 152 return self; | 
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 containerHeight -= kGeoPadding; | 396 containerHeight -= kGeoPadding; | 
| 394 | 397 | 
| 395 // Resize container to fit its subviews, and window to fit the container. | 398 // Resize container to fit its subviews, and window to fit the container. | 
| 396 NSRect windowFrame = [[self window] frame]; | 399 NSRect windowFrame = [[self window] frame]; | 
| 397 windowFrame.size.height += containerHeight - NSHeight(containerFrame); | 400 windowFrame.size.height += containerHeight - NSHeight(containerFrame); | 
| 398 [[self window] setFrame:windowFrame display:NO]; | 401 [[self window] setFrame:windowFrame display:NO]; | 
| 399 containerFrame.size.height = containerHeight; | 402 containerFrame.size.height = containerHeight; | 
| 400 [contentsContainer_ setFrame:containerFrame]; | 403 [contentsContainer_ setFrame:containerFrame]; | 
| 401 } | 404 } | 
| 402 | 405 | 
| 406 - (void)initializeProtocolHandlers { | |
| 
 
Bernhard Bauer
2012/07/02 23:13:15
I think you could generalize |initializeRadioGroup
 
Greg Billock
2012/07/03 20:33:03
Done.
 
 | |
| 407 // Configure the radio group. For now, only deal with the | |
| 408 // strictly needed case of group containing 2 radio buttons. | |
| 409 const ContentSettingBubbleModel::RadioGroup& radio_group = | |
| 410 contentSettingBubbleModel_->bubble_content().radio_group; | |
| 411 | |
| 412 // Select appropriate radio button. | |
| 413 [allowBlockRadioGroup_ selectCellWithTag: radio_group.default_item]; | |
| 414 | |
| 415 const ContentSettingBubbleModel::RadioItems& radio_items = | |
| 416 radio_group.radio_items; | |
| 417 // Set radio group labels from model. | |
| 418 for (size_t ii = 0; ii < radio_group.radio_items.size(); ++ii) { | |
| 419 NSCell* radioCell = [allowBlockRadioGroup_ cellAtRow:ii column:0]; | |
| 420 [radioCell setTitle:base::SysUTF8ToNSString(radio_items[0])]; | |
| 421 } | |
| 422 | |
| 423 // Layout radio group labels post-localization. | |
| 424 [GTMUILocalizerAndLayoutTweaker | |
| 425 wrapRadioGroupForWidth:allowBlockRadioGroup_]; | |
| 426 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker | |
| 427 sizeToFitView:allowBlockRadioGroup_].height; | |
| 428 NSRect windowFrame = [[self window] frame]; | |
| 429 windowFrame.size.height += radioDeltaY; | |
| 430 [[self window] setFrame:windowFrame display:NO]; | |
| 431 } | |
| 432 | |
| 433 | |
| 403 - (void)sizeToFitLoadButton { | 434 - (void)sizeToFitLoadButton { | 
| 404 const ContentSettingBubbleModel::BubbleContent& content = | 435 const ContentSettingBubbleModel::BubbleContent& content = | 
| 405 contentSettingBubbleModel_->bubble_content(); | 436 contentSettingBubbleModel_->bubble_content(); | 
| 406 [loadButton_ setEnabled:content.custom_link_enabled]; | 437 [loadButton_ setEnabled:content.custom_link_enabled]; | 
| 407 | 438 | 
| 408 // Resize horizontally to fit button if necessary. | 439 // Resize horizontally to fit button if necessary. | 
| 409 NSRect windowFrame = [[self window] frame]; | 440 NSRect windowFrame = [[self window] frame]; | 
| 410 int widthNeeded = NSWidth([loadButton_ frame]) + | 441 int widthNeeded = NSWidth([loadButton_ frame]) + | 
| 411 2 * NSMinX([loadButton_ frame]); | 442 2 * NSMinX([loadButton_ frame]); | 
| 412 if (NSWidth(windowFrame) < widthNeeded) { | 443 if (NSWidth(windowFrame) < widthNeeded) { | 
| (...skipping 26 matching lines...) Expand all Loading... | |
| 439 // Adapt window size to bottom buttons. Do this before all other layouting. | 470 // Adapt window size to bottom buttons. Do this before all other layouting. | 
| 440 [self sizeToFitManageDoneButtons]; | 471 [self sizeToFitManageDoneButtons]; | 
| 441 | 472 | 
| 442 [self initializeTitle]; | 473 [self initializeTitle]; | 
| 443 | 474 | 
| 444 ContentSettingsType type = contentSettingBubbleModel_->content_type(); | 475 ContentSettingsType type = contentSettingBubbleModel_->content_type(); | 
| 445 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 476 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 
| 446 [self sizeToFitLoadButton]; | 477 [self sizeToFitLoadButton]; | 
| 447 [self initializeBlockedPluginsList]; | 478 [self initializeBlockedPluginsList]; | 
| 448 } | 479 } | 
| 480 | |
| 481 if (type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | |
| 482 [self initializeProtocolHandlers]; | |
| 483 return; | |
| 484 } | |
| 485 | |
| 449 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 486 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 
| 450 [self initializeRadioGroup]; | 487 [self initializeRadioGroup]; | 
| 451 | 488 | 
| 452 if (type == CONTENT_SETTINGS_TYPE_POPUPS) | 489 if (type == CONTENT_SETTINGS_TYPE_POPUPS) | 
| 453 [self initializePopupList]; | 490 [self initializePopupList]; | 
| 454 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 491 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 
| 455 [self initializeGeoLists]; | 492 [self initializeGeoLists]; | 
| 456 } | 493 } | 
| 457 | 494 | 
| 458 /////////////////////////////////////////////////////////////////////////////// | 495 /////////////////////////////////////////////////////////////////////////////// | 
| 459 // Actual application logic | 496 // Actual application logic | 
| 460 | 497 | 
| 461 - (IBAction)allowBlockToggled:(id)sender { | 498 - (IBAction)allowBlockToggled:(id)sender { | 
| 462 NSButtonCell *selectedCell = [sender selectedCell]; | 499 NSButtonCell *selectedCell = [sender selectedCell]; | 
| 463 contentSettingBubbleModel_->OnRadioClicked( | 500 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); | 
| 464 [selectedCell tag] == kAllowTag ? 0 : 1); | |
| 465 } | 501 } | 
| 466 | 502 | 
| 467 - (void)popupLinkClicked:(id)sender { | 503 - (void)popupLinkClicked:(id)sender { | 
| 468 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 504 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 
| 469 DCHECK(i != popupLinks_.end()); | 505 DCHECK(i != popupLinks_.end()); | 
| 470 contentSettingBubbleModel_->OnPopupClicked(i->second); | 506 contentSettingBubbleModel_->OnPopupClicked(i->second); | 
| 471 } | 507 } | 
| 472 | 508 | 
| 473 - (void)clearGeolocationForCurrentHost:(id)sender { | 509 - (void)clearGeolocationForCurrentHost:(id)sender { | 
| 474 contentSettingBubbleModel_->OnCustomLinkClicked(); | 510 contentSettingBubbleModel_->OnCustomLinkClicked(); | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 491 | 527 | 
| 492 - (IBAction)manageBlocking:(id)sender { | 528 - (IBAction)manageBlocking:(id)sender { | 
| 493 contentSettingBubbleModel_->OnManageLinkClicked(); | 529 contentSettingBubbleModel_->OnManageLinkClicked(); | 
| 494 } | 530 } | 
| 495 | 531 | 
| 496 - (IBAction)closeBubble:(id)sender { | 532 - (IBAction)closeBubble:(id)sender { | 
| 497 [self close]; | 533 [self close]; | 
| 498 } | 534 } | 
| 499 | 535 | 
| 500 @end // ContentSettingBubbleController | 536 @end // ContentSettingBubbleController | 
| OLD | NEW |