| 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" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 13 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" | 13 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
| 14 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 14 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 15 #import "chrome/browser/ui/cocoa/l10n_util.h" | 15 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 16 #include "content/public/browser/plugin_service.h" | 16 #include "content/public/browser/plugin_service.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "skia/ext/skia_utils_mac.h" | 18 #include "skia/ext/skia_utils_mac.h" |
| 19 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 19 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 | 21 |
| 22 using content::PluginService; | 22 using content::PluginService; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Must match the tag of the unblock radio button in the xib files. |
| 27 const int kAllowTag = 1; |
| 28 |
| 29 // Must match the tag of the block radio button in the xib files. |
| 30 const int kBlockTag = 2; |
| 31 |
| 26 // Height of one link in the popup list. | 32 // Height of one link in the popup list. |
| 27 const int kLinkHeight = 16; | 33 const int kLinkHeight = 16; |
| 28 | 34 |
| 29 // Space between two popup links. | 35 // Space between two popup links. |
| 30 const int kLinkPadding = 4; | 36 const int kLinkPadding = 4; |
| 31 | 37 |
| 32 // Space taken in total by one popup link. | 38 // Space taken in total by one popup link. |
| 33 const int kLinkLineHeight = kLinkHeight + kLinkPadding; | 39 const int kLinkLineHeight = kLinkHeight + kLinkPadding; |
| 34 | 40 |
| 35 // Space between popup list and surrounding UI elements. | 41 // Space between popup list and surrounding UI elements. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: | 130 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: |
| 125 nibPath = @"ContentBlockedJavaScript"; break; | 131 nibPath = @"ContentBlockedJavaScript"; break; |
| 126 case CONTENT_SETTINGS_TYPE_PLUGINS: | 132 case CONTENT_SETTINGS_TYPE_PLUGINS: |
| 127 nibPath = @"ContentBlockedPlugins"; break; | 133 nibPath = @"ContentBlockedPlugins"; break; |
| 128 case CONTENT_SETTINGS_TYPE_POPUPS: | 134 case CONTENT_SETTINGS_TYPE_POPUPS: |
| 129 nibPath = @"ContentBlockedPopups"; break; | 135 nibPath = @"ContentBlockedPopups"; break; |
| 130 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 136 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 131 nibPath = @"ContentBlockedGeolocation"; break; | 137 nibPath = @"ContentBlockedGeolocation"; break; |
| 132 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: | 138 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: |
| 133 nibPath = @"ContentBlockedMixedScript"; break; | 139 nibPath = @"ContentBlockedMixedScript"; break; |
| 134 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: | |
| 135 nibPath = @"ContentProtocolHandlers"; break; | |
| 136 default: | 140 default: |
| 137 NOTREACHED(); | 141 NOTREACHED(); |
| 138 } | 142 } |
| 139 if ((self = [super initWithWindowNibPath:nibPath | 143 if ((self = [super initWithWindowNibPath:nibPath |
| 140 parentWindow:parentWindow | 144 parentWindow:parentWindow |
| 141 anchoredAt:anchoredAt])) { | 145 anchoredAt:anchoredAt])) { |
| 142 contentSettingBubbleModel_.reset(model.release()); | 146 contentSettingBubbleModel_.reset(model.release()); |
| 143 [self showWindow:nil]; | 147 [self showWindow:nil]; |
| 144 } | 148 } |
| 145 return self; | 149 return self; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 sizeToFitFixedWidthTextField:titleLabel_]; | 162 sizeToFitFixedWidthTextField:titleLabel_]; |
| 159 NSRect windowFrame = [[self window] frame]; | 163 NSRect windowFrame = [[self window] frame]; |
| 160 windowFrame.size.height += deltaY; | 164 windowFrame.size.height += deltaY; |
| 161 [[self window] setFrame:windowFrame display:NO]; | 165 [[self window] setFrame:windowFrame display:NO]; |
| 162 NSRect titleFrame = [titleLabel_ frame]; | 166 NSRect titleFrame = [titleLabel_ frame]; |
| 163 titleFrame.origin.y -= deltaY; | 167 titleFrame.origin.y -= deltaY; |
| 164 [titleLabel_ setFrame:titleFrame]; | 168 [titleLabel_ setFrame:titleFrame]; |
| 165 } | 169 } |
| 166 | 170 |
| 167 - (void)initializeRadioGroup { | 171 - (void)initializeRadioGroup { |
| 168 // NOTE! Tags in the xib files must match the order of the radio buttons | 172 // Configure the radio group. For now, only deal with the |
| 169 // passed in the radio_group and be 1-based, not 0-based. | 173 // strictly needed case of group containing 2 radio buttons. |
| 170 const ContentSettingBubbleModel::RadioGroup& radio_group = | 174 const ContentSettingBubbleModel::RadioGroup& radio_group = |
| 171 contentSettingBubbleModel_->bubble_content().radio_group; | 175 contentSettingBubbleModel_->bubble_content().radio_group; |
| 172 | 176 |
| 173 // Select appropriate radio button. | 177 // Select appropriate radio button. |
| 174 [allowBlockRadioGroup_ selectCellWithTag: radio_group.default_item + 1]; | 178 [allowBlockRadioGroup_ selectCellWithTag: |
| 179 radio_group.default_item == 0 ? kAllowTag : kBlockTag]; |
| 175 | 180 |
| 176 const ContentSettingBubbleModel::RadioItems& radio_items = | 181 const ContentSettingBubbleModel::RadioItems& radio_items = |
| 177 radio_group.radio_items; | 182 radio_group.radio_items; |
| 178 for (size_t ii = 0; ii < radio_group.radio_items.size(); ++ii) { | 183 DCHECK_EQ(2u, radio_items.size()) << "Only 2 radio items per group supported"; |
| 179 NSCell* radioCell = [allowBlockRadioGroup_ cellWithTag: ii + 1]; | 184 // Set radio group labels from model. |
| 180 [radioCell setTitle:base::SysUTF8ToNSString(radio_items[ii])]; | 185 NSCell* radioCell = [allowBlockRadioGroup_ cellWithTag:kAllowTag]; |
| 181 } | 186 [radioCell setTitle:base::SysUTF8ToNSString(radio_items[0])]; |
| 187 |
| 188 radioCell = [allowBlockRadioGroup_ cellWithTag:kBlockTag]; |
| 189 [radioCell setTitle:base::SysUTF8ToNSString(radio_items[1])]; |
| 182 | 190 |
| 183 // Layout radio group labels post-localization. | 191 // Layout radio group labels post-localization. |
| 184 [GTMUILocalizerAndLayoutTweaker | 192 [GTMUILocalizerAndLayoutTweaker |
| 185 wrapRadioGroupForWidth:allowBlockRadioGroup_]; | 193 wrapRadioGroupForWidth:allowBlockRadioGroup_]; |
| 186 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker | 194 CGFloat radioDeltaY = [GTMUILocalizerAndLayoutTweaker |
| 187 sizeToFitView:allowBlockRadioGroup_].height; | 195 sizeToFitView:allowBlockRadioGroup_].height; |
| 188 NSRect windowFrame = [[self window] frame]; | 196 NSRect windowFrame = [[self window] frame]; |
| 189 windowFrame.size.height += radioDeltaY; | 197 windowFrame.size.height += radioDeltaY; |
| 190 [[self window] setFrame:windowFrame display:NO]; | 198 [[self window] setFrame:windowFrame display:NO]; |
| 191 } | 199 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // Adapt window size to bottom buttons. Do this before all other layouting. | 439 // Adapt window size to bottom buttons. Do this before all other layouting. |
| 432 [self sizeToFitManageDoneButtons]; | 440 [self sizeToFitManageDoneButtons]; |
| 433 | 441 |
| 434 [self initializeTitle]; | 442 [self initializeTitle]; |
| 435 | 443 |
| 436 ContentSettingsType type = contentSettingBubbleModel_->content_type(); | 444 ContentSettingsType type = contentSettingBubbleModel_->content_type(); |
| 437 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 445 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 438 [self sizeToFitLoadButton]; | 446 [self sizeToFitLoadButton]; |
| 439 [self initializeBlockedPluginsList]; | 447 [self initializeBlockedPluginsList]; |
| 440 } | 448 } |
| 441 | |
| 442 if (allowBlockRadioGroup_) // not bound in cookie bubble xib | 449 if (allowBlockRadioGroup_) // not bound in cookie bubble xib |
| 443 [self initializeRadioGroup]; | 450 [self initializeRadioGroup]; |
| 444 | 451 |
| 445 if (type == CONTENT_SETTINGS_TYPE_POPUPS) | 452 if (type == CONTENT_SETTINGS_TYPE_POPUPS) |
| 446 [self initializePopupList]; | 453 [self initializePopupList]; |
| 447 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 454 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 448 [self initializeGeoLists]; | 455 [self initializeGeoLists]; |
| 449 } | 456 } |
| 450 | 457 |
| 451 /////////////////////////////////////////////////////////////////////////////// | 458 /////////////////////////////////////////////////////////////////////////////// |
| 452 // Actual application logic | 459 // Actual application logic |
| 453 | 460 |
| 454 - (IBAction)allowBlockToggled:(id)sender { | 461 - (IBAction)allowBlockToggled:(id)sender { |
| 455 NSButtonCell *selectedCell = [sender selectedCell]; | 462 NSButtonCell *selectedCell = [sender selectedCell]; |
| 456 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); | 463 contentSettingBubbleModel_->OnRadioClicked( |
| 464 [selectedCell tag] == kAllowTag ? 0 : 1); |
| 457 } | 465 } |
| 458 | 466 |
| 459 - (void)popupLinkClicked:(id)sender { | 467 - (void)popupLinkClicked:(id)sender { |
| 460 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); | 468 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); |
| 461 DCHECK(i != popupLinks_.end()); | 469 DCHECK(i != popupLinks_.end()); |
| 462 contentSettingBubbleModel_->OnPopupClicked(i->second); | 470 contentSettingBubbleModel_->OnPopupClicked(i->second); |
| 463 } | 471 } |
| 464 | 472 |
| 465 - (void)clearGeolocationForCurrentHost:(id)sender { | 473 - (void)clearGeolocationForCurrentHost:(id)sender { |
| 466 contentSettingBubbleModel_->OnCustomLinkClicked(); | 474 contentSettingBubbleModel_->OnCustomLinkClicked(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 483 | 491 |
| 484 - (IBAction)manageBlocking:(id)sender { | 492 - (IBAction)manageBlocking:(id)sender { |
| 485 contentSettingBubbleModel_->OnManageLinkClicked(); | 493 contentSettingBubbleModel_->OnManageLinkClicked(); |
| 486 } | 494 } |
| 487 | 495 |
| 488 - (IBAction)closeBubble:(id)sender { | 496 - (IBAction)closeBubble:(id)sender { |
| 489 [self close]; | 497 [self close]; |
| 490 } | 498 } |
| 491 | 499 |
| 492 @end // ContentSettingBubbleController | 500 @end // ContentSettingBubbleController |
| OLD | NEW |