| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permission_bubble/permission_bubble_controller.
h" | 5 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller.
h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/permissions/permission_request.h" | 13 #include "chrome/browser/permissions/permission_request.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 19 #import "chrome/browser/ui/cocoa/chrome_style.h" | 19 #import "chrome/browser/ui/cocoa/chrome_style.h" |
| 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 21 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 21 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
| 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 26 #include "chrome/browser/ui/cocoa/page_info/page_info_utils_cocoa.h" |
| 26 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" | 27 #include "chrome/browser/ui/cocoa/page_info/permission_selector_button.h" |
| 27 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" | 28 #include "chrome/browser/ui/cocoa/page_info/split_block_button.h" |
| 28 #include "chrome/browser/ui/cocoa/page_info/website_settings_utils_cocoa.h" | |
| 29 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" | 29 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" |
| 30 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | 30 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 31 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 31 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 32 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 32 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 33 #include "chrome/browser/ui/page_info/permission_menu_model.h" | 33 #include "chrome/browser/ui/page_info/permission_menu_model.h" |
| 34 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" | 34 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" |
| 35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 37 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
| 38 #include "components/strings/grit/components_strings.h" | 38 #include "components/strings/grit/components_strings.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 profile:(Profile*)profile { | 102 profile:(Profile*)profile { |
| 103 if (self = [super initWithFrame:NSZeroRect pullsDown:NO]) { | 103 if (self = [super initWithFrame:NSZeroRect pullsDown:NO]) { |
| 104 ContentSetting setting = | 104 ContentSetting setting = |
| 105 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 105 allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 106 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 106 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 107 [self setBordered:NO]; | 107 [self setBordered:NO]; |
| 108 | 108 |
| 109 __block PermissionPrompt::Delegate* blockDelegate = delegate; | 109 __block PermissionPrompt::Delegate* blockDelegate = delegate; |
| 110 __block AllowBlockMenuButton* blockSelf = self; | 110 __block AllowBlockMenuButton* blockSelf = self; |
| 111 PermissionMenuModel::ChangeCallback changeCallback = | 111 PermissionMenuModel::ChangeCallback changeCallback = |
| 112 base::BindBlock(^(const WebsiteSettingsUI::PermissionInfo& permission) { | 112 base::BindBlock(^(const PageInfoUI::PermissionInfo& permission) { |
| 113 blockDelegate->ToggleAccept( | 113 blockDelegate->ToggleAccept( |
| 114 index, permission.setting == CONTENT_SETTING_ALLOW); | 114 index, permission.setting == CONTENT_SETTING_ALLOW); |
| 115 [blockSelf setFrameSize: | 115 [blockSelf setFrameSize:SizeForPageInfoButtonTitle( |
| 116 SizeForWebsiteSettingsButtonTitle(blockSelf, | 116 blockSelf, [blockSelf title])]; |
| 117 [blockSelf title])]; | |
| 118 }); | 117 }); |
| 119 | 118 |
| 120 menuModel_.reset( | 119 menuModel_.reset( |
| 121 new PermissionMenuModel(profile, url, setting, changeCallback)); | 120 new PermissionMenuModel(profile, url, setting, changeCallback)); |
| 122 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() | 121 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() |
| 123 useWithPopUpButtonCell:NO]); | 122 useWithPopUpButtonCell:NO]); |
| 124 [self setMenu:[menuController_ menu]]; | 123 [self setMenu:[menuController_ menu]]; |
| 125 [self selectItemAtIndex:menuModel_->GetIndexOfCommandId(setting)]; | 124 [self selectItemAtIndex:menuModel_->GetIndexOfCommandId(setting)]; |
| 126 // Although the frame is reset, below, this sizes the cell properly. | 125 // Although the frame is reset, below, this sizes the cell properly. |
| 127 [self sizeToFit]; | 126 [self sizeToFit]; |
| 128 // Adjust the size to fit the current title. Using only -sizeToFit leaves | 127 // Adjust the size to fit the current title. Using only -sizeToFit leaves |
| 129 // an ugly amount of whitespace between the title and the arrows because it | 128 // an ugly amount of whitespace between the title and the arrows because it |
| 130 // will fit to the largest element in the menu, not just the selected item. | 129 // will fit to the largest element in the menu, not just the selected item. |
| 131 [self setFrameSize:SizeForWebsiteSettingsButtonTitle(self, [self title])]; | 130 [self setFrameSize:SizeForPageInfoButtonTitle(self, [self title])]; |
| 132 } | 131 } |
| 133 return self; | 132 return self; |
| 134 } | 133 } |
| 135 | 134 |
| 136 - (CGFloat)maximumTitleWidth { | 135 - (CGFloat)maximumTitleWidth { |
| 137 CGFloat maxTitleWidth = 0; | 136 CGFloat maxTitleWidth = 0; |
| 138 for (NSMenuItem* item in [self itemArray]) { | 137 for (NSMenuItem* item in [self itemArray]) { |
| 139 NSSize size = SizeForWebsiteSettingsButtonTitle(self, [item title]); | 138 NSSize size = SizeForPageInfoButtonTitle(self, [item title]); |
| 140 maxTitleWidth = std::max(maxTitleWidth, size.width); | 139 maxTitleWidth = std::max(maxTitleWidth, size.width); |
| 141 } | 140 } |
| 142 return maxTitleWidth; | 141 return maxTitleWidth; |
| 143 } | 142 } |
| 144 | 143 |
| 145 @end | 144 @end |
| 146 | 145 |
| 147 @interface PermissionBubbleController () | 146 @interface PermissionBubbleController () |
| 148 | 147 |
| 149 // Determines if the bubble has an anchor in a corner or no anchor at all. | 148 // Determines if the bubble has an anchor in a corner or no anchor at all. |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 658 } |
| 660 | 659 |
| 661 - (IBAction)cancel:(id)sender { | 660 - (IBAction)cancel:(id)sender { |
| 662 // This is triggered by ESC when the bubble has focus. | 661 // This is triggered by ESC when the bubble has focus. |
| 663 if (delegate_) | 662 if (delegate_) |
| 664 delegate_->Closing(); | 663 delegate_->Closing(); |
| 665 [super cancel:sender]; | 664 [super cancel:sender]; |
| 666 } | 665 } |
| 667 | 666 |
| 668 @end // implementation PermissionBubbleController | 667 @end // implementation PermissionBubbleController |
| OLD | NEW |