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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/plugins/plugin_finder.h" | 15 #include "chrome/browser/plugins/plugin_finder.h" |
16 #include "chrome/browser/plugins/plugin_metadata.h" | 16 #include "chrome/browser/plugins/plugin_metadata.h" |
17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
18 #import "chrome/browser/ui/cocoa/l10n_util.h" | 18 #import "chrome/browser/ui/cocoa/l10n_util.h" |
19 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | |
20 #import "chrome/browser/ui/cocoa/subresource_filter/subresource_filter_bubble_co ntroller.h" | |
19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 21 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
20 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" | 22 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" |
21 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | |
22 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
23 #include "components/content_settings/core/browser/host_content_settings_map.h" | 24 #include "components/content_settings/core/browser/host_content_settings_map.h" |
24 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
25 #include "content/public/browser/plugin_service.h" | 26 #include "content/public/browser/plugin_service.h" |
26 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
27 #include "skia/ext/skia_utils_mac.h" | 28 #include "skia/ext/skia_utils_mac.h" |
28 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 29 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
29 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 30 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
31 | 32 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 // close up shop. | 199 // close up shop. |
199 [controller_ closeBubble:nil]; | 200 [controller_ closeBubble:nil]; |
200 } | 201 } |
201 | 202 |
202 private: | 203 private: |
203 ContentSettingBubbleController* controller_; // weak | 204 ContentSettingBubbleController* controller_; // weak |
204 | 205 |
205 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleWebContentsObserverBridge); | 206 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleWebContentsObserverBridge); |
206 }; | 207 }; |
207 | 208 |
208 @interface ContentSettingBubbleController(Private) | 209 @interface ContentSettingBubbleController (Private) |
209 - (id)initWithModel:(ContentSettingBubbleModel*)settingsBubbleModel | 210 - (id)initWithModel:(ContentSettingBubbleModel*)settingsBubbleModel |
210 webContents:(content::WebContents*)webContents | 211 webContents:(content::WebContents*)webContents |
211 parentWindow:(NSWindow*)parentWindow | 212 parentWindow:(NSWindow*)parentWindow |
212 decoration:(ContentSettingDecoration*)decoration | 213 decoration:(ContentSettingDecoration*)decoration |
213 anchoredAt:(NSPoint)anchoredAt; | 214 anchoredAt:(NSPoint)anchoredAt; |
214 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model; | 215 + (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model; |
216 + (ContentSettingBubbleController*)getControllerForModel: | |
Robert Sesek
2017/05/03 22:05:11
Rename this too (the @implementation doesn't curre
shivanisha
2017/05/04 20:20:57
oops, done
| |
217 (ContentSettingBubbleModel*)model; | |
215 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 218 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
216 title:(NSString*)title | 219 title:(NSString*)title |
217 icon:(NSImage*)icon | 220 icon:(NSImage*)icon |
218 referenceFrame:(NSRect)referenceFrame; | 221 referenceFrame:(NSRect)referenceFrame; |
219 - (void)initializeBlockedPluginsList; | 222 - (void)initializeBlockedPluginsList; |
220 - (void)initializeTitle; | 223 - (void)initializeTitle; |
221 - (void)initializeMessage; | 224 - (void)initializeMessage; |
222 - (void)initializeRadioGroup; | 225 - (void)initializeRadioGroup; |
223 - (void)initializeItemList; | 226 - (void)initializeItemList; |
224 - (void)initializeGeoLists; | 227 - (void)initializeGeoLists; |
225 - (void)initializeMediaMenus; | 228 - (void)initializeMediaMenus; |
226 - (void)initializeMIDISysExLists; | 229 - (void)initializeMIDISysExLists; |
227 - (void)sizeToFitLoadButton; | 230 - (void)sizeToFitLoadButton; |
228 - (void)initManageDoneButtons; | 231 - (void)initManageDoneButtons; |
229 - (void)removeInfoButton; | 232 - (void)removeInfoButton; |
230 - (void)popupLinkClicked:(id)sender; | 233 - (void)popupLinkClicked:(id)sender; |
231 - (void)clearGeolocationForCurrentHost:(id)sender; | 234 - (void)clearGeolocationForCurrentHost:(id)sender; |
232 - (void)clearMIDISysExForCurrentHost:(id)sender; | 235 - (void)clearMIDISysExForCurrentHost:(id)sender; |
233 @end | 236 @end |
234 | 237 |
235 @implementation ContentSettingBubbleController | 238 @implementation ContentSettingBubbleController |
236 | 239 |
237 + (ContentSettingBubbleController*) | 240 + (ContentSettingBubbleController*) |
238 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | 241 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
239 webContents:(content::WebContents*)webContents | 242 webContents:(content::WebContents*)webContents |
240 parentWindow:(NSWindow*)parentWindow | 243 parentWindow:(NSWindow*)parentWindow |
241 decoration:(ContentSettingDecoration*)decoration | 244 decoration:(ContentSettingDecoration*)decoration |
242 anchoredAt:(NSPoint)anchor { | 245 anchoredAt:(NSPoint)anchor { |
243 // Autoreleases itself on bubble close. | 246 ContentSettingBubbleController* controller = |
Robert Sesek
2017/05/03 22:05:11
Leave this comment here.
shivanisha
2017/05/04 20:20:57
done
| |
244 return [[ContentSettingBubbleController alloc] | 247 [self allocControllerForModel:contentSettingBubbleModel]; |
245 initWithModel:contentSettingBubbleModel | 248 |
246 webContents:webContents | 249 DCHECK(controller); |
247 parentWindow:parentWindow | 250 |
248 decoration:decoration | 251 return [controller initWithModel:contentSettingBubbleModel |
249 anchoredAt:anchor]; | 252 webContents:webContents |
253 parentWindow:parentWindow | |
254 decoration:decoration | |
255 anchoredAt:anchor]; | |
250 } | 256 } |
251 | 257 |
252 struct ContentTypeToNibPath { | 258 struct ContentTypeToNibPath { |
253 ContentSettingsType type; | 259 ContentSettingsType type; |
254 NSString* path; | 260 NSString* path; |
255 }; | 261 }; |
256 | 262 |
257 const ContentTypeToNibPath kNibPaths[] = { | 263 const ContentTypeToNibPath kNibPaths[] = { |
258 {CONTENT_SETTINGS_TYPE_COOKIES, @"ContentBlockedCookies"}, | 264 {CONTENT_SETTINGS_TYPE_COOKIES, @"ContentBlockedCookies"}, |
259 {CONTENT_SETTINGS_TYPE_IMAGES, @"ContentBlockedSimple"}, | 265 {CONTENT_SETTINGS_TYPE_IMAGES, @"ContentBlockedSimple"}, |
(...skipping 11 matching lines...) Expand all Loading... | |
271 webContents:(content::WebContents*)webContents | 277 webContents:(content::WebContents*)webContents |
272 parentWindow:(NSWindow*)parentWindow | 278 parentWindow:(NSWindow*)parentWindow |
273 decoration:(ContentSettingDecoration*)decoration | 279 decoration:(ContentSettingDecoration*)decoration |
274 anchoredAt:(NSPoint)anchoredAt { | 280 anchoredAt:(NSPoint)anchoredAt { |
275 // This method takes ownership of |contentSettingBubbleModel| in all cases. | 281 // This method takes ownership of |contentSettingBubbleModel| in all cases. |
276 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); | 282 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); |
277 DCHECK(model.get()); | 283 DCHECK(model.get()); |
278 observerBridge_.reset( | 284 observerBridge_.reset( |
279 new ContentSettingBubbleWebContentsObserverBridge(webContents, self)); | 285 new ContentSettingBubbleWebContentsObserverBridge(webContents, self)); |
280 | 286 |
281 NSString* nibPath = [self getNibPathForModel:model.get()]; | 287 NSString* nibPath = |
288 [ContentSettingBubbleController getNibPathForModel:model.get()]; | |
282 | 289 |
283 DCHECK_NE(0u, [nibPath length]); | 290 DCHECK_NE(0u, [nibPath length]); |
284 | 291 |
285 if ((self = [super initWithWindowNibPath:nibPath | 292 if ((self = [super initWithWindowNibPath:nibPath |
286 parentWindow:parentWindow | 293 parentWindow:parentWindow |
287 anchoredAt:anchoredAt])) { | 294 anchoredAt:anchoredAt])) { |
288 contentSettingBubbleModel_ = std::move(model); | 295 contentSettingBubbleModel_ = std::move(model); |
289 decoration_ = decoration; | 296 decoration_ = decoration; |
290 [self showWindow:nil]; | 297 [self showWindow:nil]; |
291 } | 298 } |
292 return self; | 299 return self; |
293 } | 300 } |
294 | 301 |
295 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model { | 302 - (id)initWithModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
303 webContents:(content::WebContents*)webContents | |
304 window:(NSWindow*)window | |
305 parentWindow:(NSWindow*)parentWindow | |
306 decoration:(ContentSettingDecoration*)decoration | |
307 anchoredAt:(NSPoint)anchoredAt { | |
308 // This method takes ownership of |contentSettingBubbleModel| in all cases. | |
309 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); | |
310 DCHECK(model.get()); | |
311 observerBridge_.reset( | |
312 new ContentSettingBubbleWebContentsObserverBridge(webContents, self)); | |
313 | |
314 contentSettingBubbleModel_ = std::move(model); | |
315 | |
316 if ((self = [super initWithWindow:window | |
317 parentWindow:parentWindow | |
318 anchoredAt:anchoredAt])) { | |
319 decoration_ = decoration; | |
320 [self showWindow:nil]; | |
321 } | |
322 return self; | |
323 } | |
324 | |
325 + (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model { | |
296 NSString* nibPath = @""; | 326 NSString* nibPath = @""; |
297 | 327 |
298 ContentSettingSimpleBubbleModel* simple_bubble = model->AsSimpleBubbleModel(); | 328 ContentSettingSimpleBubbleModel* simple_bubble = model->AsSimpleBubbleModel(); |
299 if (simple_bubble) { | 329 if (simple_bubble) { |
300 ContentSettingsType settingsType = simple_bubble->content_type(); | 330 ContentSettingsType settingsType = simple_bubble->content_type(); |
301 | 331 |
302 for (const ContentTypeToNibPath& type_to_path : kNibPaths) { | 332 for (const ContentTypeToNibPath& type_to_path : kNibPaths) { |
303 if (settingsType == type_to_path.type) { | 333 if (settingsType == type_to_path.type) { |
304 nibPath = type_to_path.path; | 334 nibPath = type_to_path.path; |
305 break; | 335 break; |
306 } | 336 } |
307 } | 337 } |
308 } | 338 } |
309 | 339 |
310 if (model->AsMediaStreamBubbleModel()) | 340 if (model->AsMediaStreamBubbleModel()) |
311 nibPath = @"ContentBlockedMedia"; | 341 nibPath = @"ContentBlockedMedia"; |
312 | 342 |
313 if (model->AsSubresourceFilterBubbleModel()) | |
314 nibPath = @"ContentSubresourceFilter"; | |
315 | |
316 if (model->AsDownloadsBubbleModel()) | 343 if (model->AsDownloadsBubbleModel()) |
317 nibPath = @"ContentBlockedDownloads"; | 344 nibPath = @"ContentBlockedDownloads"; |
318 return nibPath; | 345 return nibPath; |
319 } | 346 } |
320 | 347 |
348 + (ContentSettingBubbleController*)allocControllerForModel: | |
349 (ContentSettingBubbleModel*)model { | |
350 // Check if the view is expressed in xib file or not. | |
351 NSString* nibPath = [self getNibPathForModel:model]; | |
352 | |
353 // Autoreleases itself on bubble close. | |
354 | |
355 if ([nibPath length] > 0u) | |
356 return [ContentSettingBubbleController alloc]; | |
357 | |
358 if (model->AsSubresourceFilterBubbleModel()) | |
359 return [SubresourceFilterBubbleController alloc]; | |
360 | |
361 return nil; | |
362 } | |
363 | |
321 - (void)initializeTitle { | 364 - (void)initializeTitle { |
322 if (!titleLabel_) | 365 if (!titleLabel_) |
323 return; | 366 return; |
324 | 367 |
325 NSString* label = base::SysUTF16ToNSString( | 368 NSString* label = base::SysUTF16ToNSString( |
326 contentSettingBubbleModel_->bubble_content().title); | 369 contentSettingBubbleModel_->bubble_content().title); |
327 [titleLabel_ setStringValue:label]; | 370 [titleLabel_ setStringValue:label]; |
328 | 371 |
329 // Layout title post-localization. | 372 // Layout title post-localization. |
330 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker | 373 CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 2 * NSMinX([loadButton_ frame]); | 805 2 * NSMinX([loadButton_ frame]); |
763 if (NSWidth(windowFrame) < widthNeeded) { | 806 if (NSWidth(windowFrame) < widthNeeded) { |
764 windowFrame.size.width = widthNeeded; | 807 windowFrame.size.width = widthNeeded; |
765 [[self window] setFrame:windowFrame display:NO]; | 808 [[self window] setFrame:windowFrame display:NO]; |
766 } | 809 } |
767 } | 810 } |
768 | 811 |
769 - (void)initManageDoneButtons { | 812 - (void)initManageDoneButtons { |
770 const ContentSettingBubbleModel::BubbleContent& content = | 813 const ContentSettingBubbleModel::BubbleContent& content = |
771 contentSettingBubbleModel_->bubble_content(); | 814 contentSettingBubbleModel_->bubble_content(); |
772 [manageButton_ setTitle:base::SysUTF16ToNSString(content.manage_text)]; | 815 |
773 [GTMUILocalizerAndLayoutTweaker sizeToFitView:[manageButton_ superview]]; | 816 CGFloat requiredWidthForManageButton = 0.0; |
817 if (manageButton_) { | |
818 [manageButton_ setTitle:base::SysUTF16ToNSString(content.manage_text)]; | |
819 [GTMUILocalizerAndLayoutTweaker sizeToFitView:[manageButton_ superview]]; | |
820 requiredWidthForManageButton = | |
821 NSMaxX([manageButton_ frame]) + kManageDonePadding; | |
822 } | |
823 | |
824 if (!manageButton_ && !doneButton_) | |
Robert Sesek
2017/05/03 22:05:11
Move this condition up to the beginning of the met
shivanisha
2017/05/04 20:20:57
done and made this condition as if (!done_button_)
| |
825 return; | |
826 | |
827 NSString* doneLabel = base::SysUTF16ToNSString(content.done_button_text); | |
828 if ([doneLabel length] > 0u) | |
829 [doneButton_ setTitle:doneLabel]; | |
774 | 830 |
775 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); | 831 CGFloat actualWidth = NSWidth([[[self window] contentView] frame]); |
776 CGFloat requiredWidth = NSMaxX([manageButton_ frame]) + kManageDonePadding + | 832 CGFloat requiredWidth = requiredWidthForManageButton + |
777 NSWidth([[doneButton_ superview] frame]) - NSMinX([doneButton_ frame]); | 833 NSWidth([[doneButton_ superview] frame]) - |
834 NSMinX([doneButton_ frame]); | |
778 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) | 835 if (requiredWidth <= actualWidth || !doneButton_ || !manageButton_) |
779 return; | 836 return; |
780 | 837 |
781 // Resize window, autoresizing takes care of the rest. | 838 // Resize window, autoresizing takes care of the rest. |
782 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); | 839 NSSize size = NSMakeSize(requiredWidth - actualWidth, 0); |
783 size = [[[self window] contentView] convertSize:size toView:nil]; | 840 size = [[[self window] contentView] convertSize:size toView:nil]; |
784 NSRect frame = [[self window] frame]; | 841 NSRect frame = [[self window] frame]; |
785 frame.origin.x -= size.width; | 842 frame.origin.x -= size.width; |
786 frame.size.width += size.width; | 843 frame.size.width += size.width; |
787 [[self window] setFrame:frame display:NO]; | 844 [[self window] setFrame:frame display:NO]; |
788 } | 845 } |
789 | 846 |
790 - (void)awakeFromNib { | 847 - (void)awakeFromNib { |
791 [super awakeFromNib]; | 848 [super awakeFromNib]; |
849 [self layoutView]; | |
850 } | |
792 | 851 |
852 - (void)layoutView { | |
793 ContentSettingSimpleBubbleModel* simple_bubble = | 853 ContentSettingSimpleBubbleModel* simple_bubble = |
794 contentSettingBubbleModel_->AsSimpleBubbleModel(); | 854 contentSettingBubbleModel_->AsSimpleBubbleModel(); |
795 | 855 |
796 [[self bubble] setArrowLocation:info_bubble::kTopTrailing]; | 856 [[self bubble] setArrowLocation:info_bubble::kTopTrailing]; |
797 | 857 |
798 // Adapt window size to bottom buttons. Do this before all other layouting. | 858 // Adapt window size to bottom buttons. Do this before all other layouting. |
799 if ((simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) || | 859 if ((simple_bubble && !simple_bubble->bubble_content().manage_text.empty()) || |
800 contentSettingBubbleModel_->AsDownloadsBubbleModel()) | 860 contentSettingBubbleModel_->AsDownloadsBubbleModel() || |
861 contentSettingBubbleModel_->AsSubresourceFilterBubbleModel()) { | |
801 [self initManageDoneButtons]; | 862 [self initManageDoneButtons]; |
863 } | |
802 | 864 |
803 [self initializeTitle]; | 865 [self initializeTitle]; |
804 [self initializeMessage]; | 866 [self initializeMessage]; |
805 | 867 |
806 // Note that the per-content-type methods and |initializeRadioGroup| below | 868 // Note that the per-content-type methods and |initializeRadioGroup| below |
807 // must be kept in the correct order, as they make interdependent adjustments | 869 // must be kept in the correct order, as they make interdependent adjustments |
808 // of the bubble's height. | 870 // of the bubble's height. |
809 if (simple_bubble && | 871 if (simple_bubble && |
810 simple_bubble->content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) { | 872 simple_bubble->content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) { |
811 if (!simple_bubble->bubble_content().custom_link.empty()) | 873 if (!simple_bubble->bubble_content().custom_link.empty()) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 | 978 |
917 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 979 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
918 return &mediaMenus_; | 980 return &mediaMenus_; |
919 } | 981 } |
920 | 982 |
921 - (LocationBarDecoration*)decorationForBubble { | 983 - (LocationBarDecoration*)decorationForBubble { |
922 return decoration_; | 984 return decoration_; |
923 } | 985 } |
924 | 986 |
925 @end // ContentSettingBubbleController | 987 @end // ContentSettingBubbleController |
OLD | NEW |