| 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 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 176 } |
| 177 | 177 |
| 178 @end | 178 @end |
| 179 | 179 |
| 180 @implementation WebsiteSettingsBubbleController | 180 @implementation WebsiteSettingsBubbleController |
| 181 | 181 |
| 182 - (CGFloat)defaultWindowWidth { | 182 - (CGFloat)defaultWindowWidth { |
| 183 return kDefaultWindowWidth; | 183 return kDefaultWindowWidth; |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool IsInternalURL(const GURL& url) { |
| 187 return url.SchemeIs(content::kChromeUIScheme) || |
| 188 url.SchemeIs(extensions::kExtensionScheme) || |
| 189 url.SchemeIs(content::kViewSourceScheme); |
| 190 } |
| 191 |
| 186 - (id)initWithParentWindow:(NSWindow*)parentWindow | 192 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 187 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge | 193 websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge |
| 188 webContents:(content::WebContents*)webContents | 194 webContents:(content::WebContents*)webContents |
| 189 bubbleType:(BubbleType)bubbleType | 195 url:(const GURL&)url |
| 190 isDevToolsDisabled:(BOOL)isDevToolsDisabled { | 196 isDevToolsDisabled:(BOOL)isDevToolsDisabled { |
| 191 DCHECK(parentWindow); | 197 DCHECK(parentWindow); |
| 192 | 198 |
| 193 webContents_ = webContents; | 199 webContents_ = webContents; |
| 194 permissionsPresent_ = NO; | 200 permissionsPresent_ = NO; |
| 195 isDevToolsDisabled_ = isDevToolsDisabled; | 201 isDevToolsDisabled_ = isDevToolsDisabled; |
| 202 url_ = url; |
| 196 | 203 |
| 197 // Use an arbitrary height; it will be changed in performLayout. | 204 // Use an arbitrary height; it will be changed in performLayout. |
| 198 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); | 205 NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); |
| 199 // Create an empty window into which content is placed. | 206 // Create an empty window into which content is placed. |
| 200 base::scoped_nsobject<InfoBubbleWindow> window( | 207 base::scoped_nsobject<InfoBubbleWindow> window( |
| 201 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 208 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
| 202 styleMask:NSBorderlessWindowMask | 209 styleMask:NSBorderlessWindowMask |
| 203 backing:NSBackingStoreBuffered | 210 backing:NSBackingStoreBuffered |
| 204 defer:NO]); | 211 defer:NO]); |
| 205 | 212 |
| 206 if ((self = [super initWithWindow:window.get() | 213 if ((self = [super initWithWindow:window.get() |
| 207 parentWindow:parentWindow | 214 parentWindow:parentWindow |
| 208 anchoredAt:NSZeroPoint])) { | 215 anchoredAt:NSZeroPoint])) { |
| 209 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; | 216 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; |
| 210 | 217 |
| 211 // Create the container view that uses flipped coordinates. | 218 // Create the container view that uses flipped coordinates. |
| 212 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); | 219 NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); |
| 213 contentView_.reset( | 220 contentView_.reset( |
| 214 [[FlippedView alloc] initWithFrame:contentFrame]); | 221 [[FlippedView alloc] initWithFrame:contentFrame]); |
| 215 | 222 |
| 216 // Replace the window's content. | 223 // Replace the window's content. |
| 217 [[[self window] contentView] setSubviews: | 224 [[[self window] contentView] setSubviews: |
| 218 [NSArray arrayWithObject:contentView_.get()]]; | 225 [NSArray arrayWithObject:contentView_.get()]]; |
| 219 | 226 |
| 220 if (bubbleType == INTERNAL_PAGE) | 227 if (IsInternalURL(url_)) { |
| 221 [self initializeContentsForInternalPage:false]; | 228 [self initializeContentsForInternalPage:url_]; |
| 222 else if (bubbleType == EXTENSION_PAGE) | 229 } else { |
| 223 [self initializeContentsForInternalPage:true]; | |
| 224 else | |
| 225 [self initializeContents]; | 230 [self initializeContents]; |
| 231 } |
| 226 | 232 |
| 227 bridge_.reset(bridge); | 233 bridge_.reset(bridge); |
| 228 bridge_->set_bubble_controller(self); | 234 bridge_->set_bubble_controller(self); |
| 229 } | 235 } |
| 230 return self; | 236 return self; |
| 231 } | 237 } |
| 232 | 238 |
| 233 - (void)windowWillClose:(NSNotification*)notification { | 239 - (void)windowWillClose:(NSNotification*)notification { |
| 234 if (presenter_.get()) | 240 if (presenter_.get()) |
| 235 presenter_->OnUIClosing(); | 241 presenter_->OnUIClosing(); |
| 236 presenter_.reset(); | 242 presenter_.reset(); |
| 237 [super windowWillClose:notification]; | 243 [super windowWillClose:notification]; |
| 238 } | 244 } |
| 239 | 245 |
| 240 - (void)setPresenter:(WebsiteSettings*)presenter { | 246 - (void)setPresenter:(WebsiteSettings*)presenter { |
| 241 presenter_.reset(presenter); | 247 presenter_.reset(presenter); |
| 242 } | 248 } |
| 243 | 249 |
| 244 // Create the subviews for the bubble for internal Chrome pages. | 250 // Create the subviews for the bubble for internal Chrome pages. |
| 245 - (void)initializeContentsForInternalPage:(BOOL)isExtensionPage { | 251 - (void)initializeContentsForInternalPage:(const GURL&)url { |
| 246 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 252 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 247 | 253 |
| 248 NSPoint controlOrigin = NSMakePoint( | 254 int text = IDS_PAGE_INFO_INTERNAL_PAGE; |
| 249 kInternalPageFramePadding, | 255 int icon = IDR_PRODUCT_LOGO_16; |
| 250 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight); | 256 if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 251 NSImage* productLogoImage = | 257 text = IDS_PAGE_INFO_EXTENSION_PAGE; |
| 252 rb.GetNativeImageNamed(isExtensionPage ? IDR_PLUGINS_FAVICON | 258 icon = IDR_PLUGINS_FAVICON; |
| 253 : IDR_PRODUCT_LOGO_16) | 259 } else if (url.SchemeIs(content::kViewSourceScheme)) { |
| 254 .ToNSImage(); | 260 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE; |
| 261 // view-source scheme uses the same icon as chrome:// pages. |
| 262 icon = IDR_PRODUCT_LOGO_16; |
| 263 } else if (!url.SchemeIs(content::kChromeUIScheme)) { |
| 264 NOTREACHED(); |
| 265 } |
| 266 |
| 267 NSPoint controlOrigin = |
| 268 NSMakePoint(kInternalPageFramePadding, |
| 269 kInternalPageFramePadding + info_bubble::kBubbleArrowHeight); |
| 270 NSImage* productLogoImage = rb.GetNativeImageNamed(icon).ToNSImage(); |
| 255 NSImageView* imageView = [self addImageWithSize:[productLogoImage size] | 271 NSImageView* imageView = [self addImageWithSize:[productLogoImage size] |
| 256 toView:contentView_ | 272 toView:contentView_ |
| 257 atPoint:controlOrigin]; | 273 atPoint:controlOrigin]; |
| 258 [imageView setImage:productLogoImage]; | 274 [imageView setImage:productLogoImage]; |
| 259 | 275 |
| 260 NSRect imageFrame = [imageView frame]; | 276 NSRect imageFrame = [imageView frame]; |
| 261 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing; | 277 controlOrigin.x += NSWidth(imageFrame) + kInternalPageImageSpacing; |
| 262 base::string16 text = | 278 NSTextField* textField = [self addText:l10n_util::GetStringUTF16(text) |
| 263 l10n_util::GetStringUTF16(isExtensionPage ? IDS_PAGE_INFO_EXTENSION_PAGE | |
| 264 : IDS_PAGE_INFO_INTERNAL_PAGE); | |
| 265 NSTextField* textField = [self addText:text | |
| 266 withSize:[NSFont smallSystemFontSize] | 279 withSize:[NSFont smallSystemFontSize] |
| 267 bold:NO | 280 bold:NO |
| 268 toView:contentView_ | 281 toView:contentView_ |
| 269 atPoint:controlOrigin]; | 282 atPoint:controlOrigin]; |
| 270 // Center the image vertically with the text. Previously this code centered | 283 // Center the image vertically with the text. Previously this code centered |
| 271 // the text vertically while holding the image in place. That produced correct | 284 // the text vertically while holding the image in place. That produced correct |
| 272 // results when the image, at 26x26, was taller than (or just slightly | 285 // results when the image, at 26x26, was taller than (or just slightly |
| 273 // shorter) than the text, but produced incorrect results once the icon | 286 // shorter) than the text, but produced incorrect results once the icon |
| 274 // shrank to 16x16. The icon should now always be shorter than the text. | 287 // shrank to 16x16. The icon should now always be shorter than the text. |
| 275 // See crbug.com/572044 . | 288 // See crbug.com/572044 . |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 web_contents, virtual_url, security_info); | 1140 web_contents, virtual_url, security_info); |
| 1128 return; | 1141 return; |
| 1129 } | 1142 } |
| 1130 | 1143 |
| 1131 // Don't show the popup if it's already being shown. Since this method is | 1144 // Don't show the popup if it's already being shown. Since this method is |
| 1132 // called each time the location icon is clicked, each click toggles the popup | 1145 // called each time the location icon is clicked, each click toggles the popup |
| 1133 // in and out. | 1146 // in and out. |
| 1134 if (g_is_popup_showing) | 1147 if (g_is_popup_showing) |
| 1135 return; | 1148 return; |
| 1136 | 1149 |
| 1137 BubbleType bubble_type = WEB_PAGE; | |
| 1138 if (virtual_url.SchemeIs(content::kChromeUIScheme)) | |
| 1139 bubble_type = INTERNAL_PAGE; | |
| 1140 else if (virtual_url.SchemeIs(extensions::kExtensionScheme)) | |
| 1141 bubble_type = EXTENSION_PAGE; | |
| 1142 | |
| 1143 // Create the bridge. This will be owned by the bubble controller. | 1150 // Create the bridge. This will be owned by the bubble controller. |
| 1144 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); | 1151 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(web_contents); |
| 1145 | 1152 |
| 1146 bool is_devtools_disabled = | 1153 bool is_devtools_disabled = |
| 1147 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); | 1154 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
| 1148 | 1155 |
| 1149 // Create the bubble controller. It will dealloc itself when it closes, | 1156 // Create the bubble controller. It will dealloc itself when it closes, |
| 1150 // resetting |g_is_popup_showing|. | 1157 // resetting |g_is_popup_showing|. |
| 1151 WebsiteSettingsBubbleController* bubble_controller = | 1158 WebsiteSettingsBubbleController* bubble_controller = |
| 1152 [[WebsiteSettingsBubbleController alloc] | 1159 [[WebsiteSettingsBubbleController alloc] |
| 1153 initWithParentWindow:parent | 1160 initWithParentWindow:parent |
| 1154 websiteSettingsUIBridge:bridge | 1161 websiteSettingsUIBridge:bridge |
| 1155 webContents:web_contents | 1162 webContents:web_contents |
| 1156 bubbleType:bubble_type | 1163 url:virtual_url |
| 1157 isDevToolsDisabled:is_devtools_disabled]; | 1164 isDevToolsDisabled:is_devtools_disabled]; |
| 1158 | 1165 |
| 1159 if (bubble_type == WEB_PAGE) { | 1166 if (!IsInternalURL(virtual_url)) { |
| 1160 // Initialize the presenter, which holds the model and controls the UI. | 1167 // Initialize the presenter, which holds the model and controls the UI. |
| 1161 // This is also owned by the bubble controller. | 1168 // This is also owned by the bubble controller. |
| 1162 WebsiteSettings* presenter = new WebsiteSettings( | 1169 WebsiteSettings* presenter = new WebsiteSettings( |
| 1163 bridge, profile, | 1170 bridge, profile, |
| 1164 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, | 1171 TabSpecificContentSettings::FromWebContents(web_contents), web_contents, |
| 1165 virtual_url, security_info, content::CertStore::GetInstance()); | 1172 virtual_url, security_info, content::CertStore::GetInstance()); |
| 1166 [bubble_controller setPresenter:presenter]; | 1173 [bubble_controller setPresenter:presenter]; |
| 1167 } | 1174 } |
| 1168 | 1175 |
| 1169 [bubble_controller showWindow:nil]; | 1176 [bubble_controller showWindow:nil]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1189 void WebsiteSettingsUIBridge::SetPermissionInfo( | 1196 void WebsiteSettingsUIBridge::SetPermissionInfo( |
| 1190 const PermissionInfoList& permission_info_list, | 1197 const PermissionInfoList& permission_info_list, |
| 1191 const ChosenObjectInfoList& chosen_object_info_list) { | 1198 const ChosenObjectInfoList& chosen_object_info_list) { |
| 1192 [bubble_controller_ setPermissionInfo:permission_info_list | 1199 [bubble_controller_ setPermissionInfo:permission_info_list |
| 1193 andChosenObjects:chosen_object_info_list]; | 1200 andChosenObjects:chosen_object_info_list]; |
| 1194 } | 1201 } |
| 1195 | 1202 |
| 1196 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { | 1203 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { |
| 1197 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) | 1204 // TODO(lgarron): Remove this from the interface. (crbug.com/571533) |
| 1198 } | 1205 } |
| OLD | NEW |