| 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 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 20 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" | 20 #include "chrome/browser/ui/content_settings/content_setting_media_menu_model.h" |
| 21 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/content_settings/core/browser/host_content_settings_map.h" | 23 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 23 #include "content/public/browser/plugin_service.h" | 24 #include "content/public/browser/plugin_service.h" |
| 24 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
| 25 #include "skia/ext/skia_utils_mac.h" | 26 #include "skia/ext/skia_utils_mac.h" |
| 26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 27 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 27 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 28 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 29 | 30 |
| 30 using content::PluginService; | 31 using content::PluginService; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 private: | 198 private: |
| 198 ContentSettingBubbleController* controller_; // weak | 199 ContentSettingBubbleController* controller_; // weak |
| 199 | 200 |
| 200 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleWebContentsObserverBridge); | 201 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleWebContentsObserverBridge); |
| 201 }; | 202 }; |
| 202 | 203 |
| 203 @interface ContentSettingBubbleController(Private) | 204 @interface ContentSettingBubbleController(Private) |
| 204 - (id)initWithModel:(ContentSettingBubbleModel*)settingsBubbleModel | 205 - (id)initWithModel:(ContentSettingBubbleModel*)settingsBubbleModel |
| 205 webContents:(content::WebContents*)webContents | 206 webContents:(content::WebContents*)webContents |
| 206 parentWindow:(NSWindow*)parentWindow | 207 parentWindow:(NSWindow*)parentWindow |
| 208 decoration:(ContentSettingDecoration*)decoration |
| 207 anchoredAt:(NSPoint)anchoredAt; | 209 anchoredAt:(NSPoint)anchoredAt; |
| 208 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model; | 210 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model; |
| 209 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame | 211 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame |
| 210 title:(NSString*)title | 212 title:(NSString*)title |
| 211 icon:(NSImage*)icon | 213 icon:(NSImage*)icon |
| 212 referenceFrame:(NSRect)referenceFrame; | 214 referenceFrame:(NSRect)referenceFrame; |
| 213 - (void)initializeBlockedPluginsList; | 215 - (void)initializeBlockedPluginsList; |
| 214 - (void)initializeTitle; | 216 - (void)initializeTitle; |
| 215 - (void)initializeMessage; | 217 - (void)initializeMessage; |
| 216 - (void)initializeRadioGroup; | 218 - (void)initializeRadioGroup; |
| 217 - (void)initializeItemList; | 219 - (void)initializeItemList; |
| 218 - (void)initializeGeoLists; | 220 - (void)initializeGeoLists; |
| 219 - (void)initializeMediaMenus; | 221 - (void)initializeMediaMenus; |
| 220 - (void)initializeMIDISysExLists; | 222 - (void)initializeMIDISysExLists; |
| 221 - (void)sizeToFitLoadButton; | 223 - (void)sizeToFitLoadButton; |
| 222 - (void)initManageDoneButtons; | 224 - (void)initManageDoneButtons; |
| 223 - (void)removeInfoButton; | 225 - (void)removeInfoButton; |
| 224 - (void)popupLinkClicked:(id)sender; | 226 - (void)popupLinkClicked:(id)sender; |
| 225 - (void)clearGeolocationForCurrentHost:(id)sender; | 227 - (void)clearGeolocationForCurrentHost:(id)sender; |
| 226 - (void)clearMIDISysExForCurrentHost:(id)sender; | 228 - (void)clearMIDISysExForCurrentHost:(id)sender; |
| 227 @end | 229 @end |
| 228 | 230 |
| 229 @implementation ContentSettingBubbleController | 231 @implementation ContentSettingBubbleController |
| 230 | 232 |
| 231 + (ContentSettingBubbleController*) | 233 + (ContentSettingBubbleController*) |
| 232 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | 234 showForModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
| 233 webContents:(content::WebContents*)webContents | 235 webContents:(content::WebContents*)webContents |
| 234 parentWindow:(NSWindow*)parentWindow | 236 parentWindow:(NSWindow*)parentWindow |
| 235 anchoredAt:(NSPoint)anchor { | 237 decoration:(ContentSettingDecoration*)decoration |
| 238 anchoredAt:(NSPoint)anchor { |
| 236 // Autoreleases itself on bubble close. | 239 // Autoreleases itself on bubble close. |
| 237 return [[ContentSettingBubbleController alloc] | 240 return [[ContentSettingBubbleController alloc] |
| 238 initWithModel:contentSettingBubbleModel | 241 initWithModel:contentSettingBubbleModel |
| 239 webContents:webContents | 242 webContents:webContents |
| 240 parentWindow:parentWindow | 243 parentWindow:parentWindow |
| 241 anchoredAt:anchor]; | 244 decoration:decoration |
| 245 anchoredAt:anchor]; |
| 242 } | 246 } |
| 243 | 247 |
| 244 struct ContentTypeToNibPath { | 248 struct ContentTypeToNibPath { |
| 245 ContentSettingsType type; | 249 ContentSettingsType type; |
| 246 NSString* path; | 250 NSString* path; |
| 247 }; | 251 }; |
| 248 | 252 |
| 249 const ContentTypeToNibPath kNibPaths[] = { | 253 const ContentTypeToNibPath kNibPaths[] = { |
| 250 {CONTENT_SETTINGS_TYPE_COOKIES, @"ContentBlockedCookies"}, | 254 {CONTENT_SETTINGS_TYPE_COOKIES, @"ContentBlockedCookies"}, |
| 251 {CONTENT_SETTINGS_TYPE_IMAGES, @"ContentBlockedSimple"}, | 255 {CONTENT_SETTINGS_TYPE_IMAGES, @"ContentBlockedSimple"}, |
| 252 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, @"ContentBlockedSimple"}, | 256 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, @"ContentBlockedSimple"}, |
| 253 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, @"ContentBlockedSimple"}, | 257 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, @"ContentBlockedSimple"}, |
| 254 {CONTENT_SETTINGS_TYPE_PLUGINS, @"ContentBlockedPlugins"}, | 258 {CONTENT_SETTINGS_TYPE_PLUGINS, @"ContentBlockedPlugins"}, |
| 255 {CONTENT_SETTINGS_TYPE_POPUPS, @"ContentBlockedPopups"}, | 259 {CONTENT_SETTINGS_TYPE_POPUPS, @"ContentBlockedPopups"}, |
| 256 {CONTENT_SETTINGS_TYPE_GEOLOCATION, @"ContentBlockedGeolocation"}, | 260 {CONTENT_SETTINGS_TYPE_GEOLOCATION, @"ContentBlockedGeolocation"}, |
| 257 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, @"ContentBlockedMixedScript"}, | 261 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, @"ContentBlockedMixedScript"}, |
| 258 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, @"ContentProtocolHandlers"}, | 262 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, @"ContentProtocolHandlers"}, |
| 259 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, @"ContentBlockedDownloads"}, | 263 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, @"ContentBlockedDownloads"}, |
| 260 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, @"ContentBlockedMIDISysEx"}, | 264 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, @"ContentBlockedMIDISysEx"}, |
| 261 }; | 265 }; |
| 262 | 266 |
| 263 - (id)initWithModel:(ContentSettingBubbleModel*)contentSettingBubbleModel | 267 - (id)initWithModel:(ContentSettingBubbleModel*)contentSettingBubbleModel |
| 264 webContents:(content::WebContents*)webContents | 268 webContents:(content::WebContents*)webContents |
| 265 parentWindow:(NSWindow*)parentWindow | 269 parentWindow:(NSWindow*)parentWindow |
| 270 decoration:(ContentSettingDecoration*)decoration |
| 266 anchoredAt:(NSPoint)anchoredAt { | 271 anchoredAt:(NSPoint)anchoredAt { |
| 267 // This method takes ownership of |contentSettingBubbleModel| in all cases. | 272 // This method takes ownership of |contentSettingBubbleModel| in all cases. |
| 268 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); | 273 std::unique_ptr<ContentSettingBubbleModel> model(contentSettingBubbleModel); |
| 269 DCHECK(model.get()); | 274 DCHECK(model.get()); |
| 270 observerBridge_.reset( | 275 observerBridge_.reset( |
| 271 new ContentSettingBubbleWebContentsObserverBridge(webContents, self)); | 276 new ContentSettingBubbleWebContentsObserverBridge(webContents, self)); |
| 272 | 277 |
| 273 NSString* nibPath = [self getNibPathForModel:model.get()]; | 278 NSString* nibPath = [self getNibPathForModel:model.get()]; |
| 274 | 279 |
| 275 DCHECK_NE(0u, [nibPath length]); | 280 DCHECK_NE(0u, [nibPath length]); |
| 276 | 281 |
| 277 if ((self = [super initWithWindowNibPath:nibPath | 282 if ((self = [super initWithWindowNibPath:nibPath |
| 278 parentWindow:parentWindow | 283 parentWindow:parentWindow |
| 279 anchoredAt:anchoredAt])) { | 284 anchoredAt:anchoredAt])) { |
| 280 contentSettingBubbleModel_.reset(model.release()); | 285 contentSettingBubbleModel_.reset(model.release()); |
| 286 decoration_ = decoration; |
| 281 [self showWindow:nil]; | 287 [self showWindow:nil]; |
| 282 } | 288 } |
| 283 return self; | 289 return self; |
| 284 } | 290 } |
| 285 | 291 |
| 286 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model { | 292 - (NSString*)getNibPathForModel:(ContentSettingBubbleModel*)model { |
| 287 NSString* nibPath = @""; | 293 NSString* nibPath = @""; |
| 288 | 294 |
| 289 ContentSettingSimpleBubbleModel* simple_bubble = model->AsSimpleBubbleModel(); | 295 ContentSettingSimpleBubbleModel* simple_bubble = model->AsSimpleBubbleModel(); |
| 290 if (simple_bubble) { | 296 if (simple_bubble) { |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 SetTitleForPopUpButton( | 876 SetTitleForPopUpButton( |
| 871 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); | 877 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); |
| 872 | 878 |
| 873 it->second->model->ExecuteCommand(index, 0); | 879 it->second->model->ExecuteCommand(index, 0); |
| 874 } | 880 } |
| 875 | 881 |
| 876 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { | 882 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { |
| 877 return &mediaMenus_; | 883 return &mediaMenus_; |
| 878 } | 884 } |
| 879 | 885 |
| 886 - (LocationBarDecoration*)decorationForBubble { |
| 887 return decoration_; |
| 888 } |
| 889 |
| 880 @end // ContentSettingBubbleController | 890 @end // ContentSettingBubbleController |
| OLD | NEW |