| 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/website_settings/website_settings_bubble_contro
ller.h" | 5 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro
ller.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/mac/bind_objc_block.h" | 12 #include "base/mac/bind_objc_block.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #import "chrome/browser/certificate_viewer.h" | 16 #import "chrome/browser/certificate_viewer.h" |
| 17 #include "chrome/browser/devtools/devtools_toggle_action.h" | 17 #include "chrome/browser/devtools/devtools_toggle_action.h" |
| 18 #include "chrome/browser/devtools/devtools_window.h" | 18 #include "chrome/browser/devtools/devtools_window.h" |
| 19 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser_dialogs.h" | 21 #include "chrome/browser/ui/browser_dialogs.h" |
| 22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 23 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 24 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 24 #import "chrome/browser/ui/cocoa/info_bubble_window.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 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 26 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
| 27 #import "chrome/browser/ui/tab_dialogs.h" | 27 #import "chrome/browser/ui/tab_dialogs.h" |
| 28 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 28 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 29 #include "chrome/browser/ui/website_settings/website_settings_utils.h" | |
| 30 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/grit/chromium_strings.h" | 31 #include "chrome/grit/chromium_strings.h" |
| 33 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 34 #include "chrome/grit/theme_resources.h" | 33 #include "chrome/grit/theme_resources.h" |
| 35 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 36 #include "content/public/browser/cert_store.h" | 35 #include "content/public/browser/cert_store.h" |
| 37 #include "content/public/browser/page_navigator.h" | 36 #include "content/public/browser/page_navigator.h" |
| 38 #include "content/public/browser/ssl_host_state_delegate.h" | 37 #include "content/public/browser/ssl_host_state_delegate.h" |
| 39 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/common/url_constants.h" |
| 41 #include "extensions/common/constants.h" |
| 41 #include "grit/components_chromium_strings.h" | 42 #include "grit/components_chromium_strings.h" |
| 42 #include "grit/components_google_chrome_strings.h" | 43 #include "grit/components_google_chrome_strings.h" |
| 43 #include "grit/components_strings.h" | 44 #include "grit/components_strings.h" |
| 44 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 45 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 45 #include "ui/base/cocoa/cocoa_base_utils.h" | 46 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 46 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 47 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 47 #import "ui/base/cocoa/flipped_view.h" | 48 #import "ui/base/cocoa/flipped_view.h" |
| 48 #import "ui/base/cocoa/hover_image_button.h" | 49 #import "ui/base/cocoa/hover_image_button.h" |
| 49 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 50 #include "ui/base/resource/resource_bundle.h" | 51 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 176 |
| 176 @implementation WebsiteSettingsBubbleController | 177 @implementation WebsiteSettingsBubbleController |
| 177 | 178 |
| 178 - (CGFloat)defaultWindowWidth { | 179 - (CGFloat)defaultWindowWidth { |
| 179 return kDefaultWindowWidth; | 180 return kDefaultWindowWidth; |
| 180 } | 181 } |
| 181 | 182 |
| 182 - (id)initWithParentWindow:(NSWindow*)parentWindow | 183 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 183 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge | 184 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge |
| 184 webContents:(content::WebContents*)webContents | 185 webContents:(content::WebContents*)webContents |
| 185 isInternalPage:(BOOL)isInternalPage | 186 bubbleType:(BubbleType)bubbleType |
| 186 isDevToolsDisabled:(BOOL)isDevToolsDisabled { | 187 isDevToolsDisabled:(BOOL)isDevToolsDisabled { |
| 187 DCHECK(parentWindow); | 188 DCHECK(parentWindow); |
| 188 | 189 |
| 189 webContents_ = webContents; | 190 webContents_ = webContents; |
| 190 permissionsPresent_ = NO; | 191 permissionsPresent_ = NO; |
| 191 isDevToolsDisabled_ = isDevToolsDisabled; | 192 isDevToolsDisabled_ = isDevToolsDisabled; |
| 192 | 193 |
| 193 // Use an arbitrary height; it will be changed in performLayout. | 194 // Use an arbitrary height; it will be changed in performLayout. |
| 194 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); | 195 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); |
| 195 // Create an empty window into which content is placed. | 196 // Create an empty window into which content is placed. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 206 | 207 |
| 207 // Create the container view that uses flipped coordinates. | 208 // Create the container view that uses flipped coordinates. |
| 208 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); | 209 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); |
| 209 contentView_.reset( | 210 contentView_.reset( |
| 210 [[FlippedView alloc] initWithFrame:contentFrame]); | 211 [[FlippedView alloc] initWithFrame:contentFrame]); |
| 211 | 212 |
| 212 // Replace the window's content. | 213 // Replace the window's content. |
| 213 [[[self window] contentView] setSubviews: | 214 [[[self window] contentView] setSubviews: |
| 214 [NSArray arrayWithObject:contentView_.get()]]; | 215 [NSArray arrayWithObject:contentView_.get()]]; |
| 215 | 216 |
| 216 if (isInternalPage) | 217 if (bubbleType == INTERNAL_PAGE) |
| 217 [self initializeContentsForInternalPage]; | 218 [self initializeContentsForInternalPage:false]; |
| 219 else if (bubbleType == EXTENSION_PAGE) |
| 220 [self initializeContentsForInternalPage:true]; |
| 218 else | 221 else |
| 219 [self initializeContents]; | 222 [self initializeContents]; |
| 220 | 223 |
| 221 bridge_.reset(bridge); | 224 bridge_.reset(bridge); |
| 222 bridge_->set_bubble_controller(self); | 225 bridge_->set_bubble_controller(self); |
| 223 } | 226 } |
| 224 return self; | 227 return self; |
| 225 } | 228 } |
| 226 | 229 |
| 227 - (void)windowWillClose:(NSNotification*)notification { | 230 - (void)windowWillClose:(NSNotification*)notification { |
| 228 if (presenter_.get()) | 231 if (presenter_.get()) |
| 229 presenter_->OnUIClosing(); | 232 presenter_->OnUIClosing(); |
| 230 presenter_.reset(); | 233 presenter_.reset(); |
| 231 [super windowWillClose:notification]; | 234 [super windowWillClose:notification]; |
| 232 } | 235 } |
| 233 | 236 |
| 234 - (void)setPresenter:(WebsiteSettings*)presenter { | 237 - (void)setPresenter:(WebsiteSettings*)presenter { |
| 235 presenter_.reset(presenter); | 238 presenter_.reset(presenter); |
| 236 } | 239 } |
| 237 | 240 |
| 238 // Create the subviews for the bubble for internal Chrome pages. | 241 // Create the subviews for the bubble for internal Chrome pages. |
| 239 - (void)initializeContentsForInternalPage { | 242 - (void)initializeContentsForInternalPage:(BOOL)isExtensionPage { |
| 240 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 241 | 244 |
| 242 NSPoint controlOrigin = NSMakePoint( | 245 NSPoint controlOrigin = NSMakePoint( |
| 243 kInternalPageFramePadding, | 246 kInternalPageFramePadding, |
| 244 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight); | 247 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight); |
| 245 NSImage* productLogoImage = | 248 NSImage* productLogoImage = |
| 246 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToNSImage(); | 249 rb.GetNativeImageNamed(isExtensionPage ? IDR_PLUGINS_FAVICON |
| 250 : IDR_PRODUCT_LOGO_16) |
| 251 .ToNSImage(); |
| 247 NSImageView* imageView = [self addImageWithSize:[productLogoImage size] | 252 NSImageView* imageView = [self addImageWithSize:[productLogoImage size] |
| 248 toView:contentView_ | 253 toView:contentView_ |
| 249 atPoint:controlOrigin]; | 254 atPoint:controlOrigin]; |
| 250 [imageView setImage:productLogoImage]; | 255 [imageView setImage:productLogoImage]; |
| 251 | 256 |
| 252 NSRect imageFrame = [imageView frame]; | 257 NSRect imageFrame = [imageView frame]; |
| 253 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing; | 258 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing; |
| 254 base::string16 text = l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); | 259 base::string16 text = |
| 260 l10n_util::GetStringUTF16(isExtensionPage ? IDS_PAGE_INFO_EXTENSION_PAGE |
| 261 : IDS_PAGE_INFO_INTERNAL_PAGE); |
| 255 NSTextField* textField = [self addText:text | 262 NSTextField* textField = [self addText:text |
| 256 withSize:[NSFont smallSystemFontSize] | 263 withSize:[NSFont smallSystemFontSize] |
| 257 bold:NO | 264 bold:NO |
| 258 toView:contentView_ | 265 toView:contentView_ |
| 259 atPoint:controlOrigin]; | 266 atPoint:controlOrigin]; |
| 260 // Center the image vertically with the text. Previously this code centered | 267 // Center the image vertically with the text. Previously this code centered |
| 261 // the text vertically while holding the image in place. That produced correct | 268 // the text vertically while holding the image in place. That produced correct |
| 262 // results when the image, at 26x26, was taller than (or just slightly | 269 // results when the image, at 26x26, was taller than (or just slightly |
| 263 // shorter) than the text, but produced incorrect results once the icon | 270 // shorter) than the text, but produced incorrect results once the icon |
| 264 // shrank to 16x16. The icon should now always be shorter than the text. | 271 // shrank to 16x16. The icon should now always be shorter than the text. |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 content::WebContents* web_contents, | 1115 content::WebContents* web_contents, |
| 1109 const GURL& url, | 1116 const GURL& url, |
| 1110 const security_state::SecurityStateModel::SecurityInfo& security_info) { | 1117 const security_state::SecurityStateModel::SecurityInfo& security_info) { |
| 1111 if (chrome::ToolkitViewsDialogsEnabled()) { | 1118 if (chrome::ToolkitViewsDialogsEnabled()) { |
| 1112 chrome::ShowWebsiteSettingsBubbleViewsAtPoint( | 1119 chrome::ShowWebsiteSettingsBubbleViewsAtPoint( |
| 1113 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, | 1120 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, |
| 1114 web_contents, url, security_info); | 1121 web_contents, url, security_info); |
| 1115 return; | 1122 return; |
| 1116 } | 1123 } |
| 1117 | 1124 |
| 1118 bool is_internal_page = InternalChromePage(url); | 1125 BubbleType bubble_type = WEB_PAGE; |
| 1126 if (url.SchemeIs(content::kChromeUIScheme)) |
| 1127 bubble_type = INTERNAL_PAGE; |
| 1128 else if (url.SchemeIs(extensions::kExtensionScheme)) |
| 1129 bubble_type = EXTENSION_PAGE; |
| 1119 | 1130 |
| 1120 // Create the bridge. This will be owned by the bubble controller. | 1131 // Create the bridge. This will be owned by the bubble controller. |
| 1121 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); | 1132 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); |
| 1122 | 1133 |
| 1123 bool is_devtools_disabled = | 1134 bool is_devtools_disabled = |
| 1124 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); | 1135 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
| 1125 | 1136 |
| 1126 // Create the bubble controller. It will dealloc itself when it closes. | 1137 // Create the bubble controller. It will dealloc itself when it closes. |
| 1127 WebsiteSettingsBubbleController* bubble_controller = | 1138 WebsiteSettingsBubbleController* bubble_controller = |
| 1128 [[WebsiteSettingsBubbleController alloc] | 1139 [[WebsiteSettingsBubbleController alloc] |
| 1129 initWithParentWindow:parent | 1140 initWithParentWindow:parent |
| 1130 websiteSettingsUIBridge:bridge | 1141 websiteSettingsUIBridge:bridge |
| 1131 webContents:web_contents | 1142 webContents:web_contents |
| 1132 isInternalPage:is_internal_page | 1143 bubbleType:bubble_type |
| 1133 isDevToolsDisabled:is_devtools_disabled]; | 1144 isDevToolsDisabled:is_devtools_disabled]; |
| 1134 | 1145 |
| 1135 if (!is_internal_page) { | 1146 if (bubble_type == WEB_PAGE) { |
| 1136 // Initialize the presenter, which holds the model and controls the UI. | 1147 // Initialize the presenter, which holds the model and controls the UI. |
| 1137 // This is also owned by the bubble controller. | 1148 // This is also owned by the bubble controller. |
| 1138 WebsiteSettings* presenter = new WebsiteSettings( | 1149 WebsiteSettings* presenter = new WebsiteSettings( |
| 1139 bridge, profile, | 1150 bridge, profile, |
| 1140 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, | 1151 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, |
| 1141 url, security_info, content::CertStore::GetInstance()); | 1152 url, security_info, content::CertStore::GetInstance()); |
| 1142 [bubble_controller setPresenter:presenter]; | 1153 [bubble_controller setPresenter:presenter]; |
| 1143 } | 1154 } |
| 1144 | 1155 |
| 1145 [bubble_controller showWindow:nil]; | 1156 [bubble_controller showWindow:nil]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1165 void WebsiteSettingsUIBridge::SetPermissionInfo( | 1176 void WebsiteSettingsUIBridge::SetPermissionInfo( |
| 1166 const PermissionInfoList& permission_info_list, | 1177 const PermissionInfoList& permission_info_list, |
| 1167 const ChosenObjectInfoList& chosen_object_info_list) { | 1178 const ChosenObjectInfoList& chosen_object_info_list) { |
| 1168 [bubble_controller_ setPermissionInfo:permission_info_list | 1179 [bubble_controller_ setPermissionInfo:permission_info_list |
| 1169 andChosenObjects:chosen_object_info_list]; | 1180 andChosenObjects:chosen_object_info_list]; |
| 1170 } | 1181 } |
| 1171 | 1182 |
| 1172 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { | 1183 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { |
| 1173 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) | 1184 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) |
| 1174 } | 1185 } |
| OLD | NEW |