| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/notifications/notification_options_menu_model.h" | 5 #include "chrome/browser/notifications/notification_options_menu_model.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/notifications/balloon_collection.h" | 13 #include "chrome/browser/notifications/balloon_collection.h" |
| 14 #include "chrome/browser/notifications/balloon_host.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 17 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 18 #include "chrome/browser/notifications/notifications_prefs_cache.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/content_settings_types.h" | 21 #include "chrome/common/content_settings_types.h" |
| 21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/tab_contents/tab_contents.h" |
| 23 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 25 | 27 |
| 26 #if defined(OS_WIN) | |
| 27 #include "chrome/browser/ui/views/browser_dialogs.h" | |
| 28 #endif // OS_WIN | |
| 29 | |
| 30 // Menu commands | 28 // Menu commands |
| 31 const int kTogglePermissionCommand = 0; | 29 const int kTogglePermissionCommand = 0; |
| 32 const int kToggleExtensionCommand = 1; | 30 const int kToggleExtensionCommand = 1; |
| 33 const int kOpenContentSettingsCommand = 2; | 31 const int kOpenContentSettingsCommand = 2; |
| 34 const int kCornerSelectionSubMenu = 3; | 32 const int kCornerSelectionSubMenu = 3; |
| 35 | 33 |
| 36 const int kCornerGroupId = 10; | 34 const int kCornerGroupId = 10; |
| 37 const int kCornerUpperLeft = 11; | 35 const int kCornerUpperLeft = 11; |
| 38 const int kCornerUpperRight = 12; | 36 const int kCornerUpperRight = 12; |
| 39 const int kCornerLowerLeft = 13; | 37 const int kCornerLowerLeft = 13; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 145 } |
| 148 | 146 |
| 149 bool NotificationOptionsMenuModel::IsItemForCommandIdDynamic(int command_id) | 147 bool NotificationOptionsMenuModel::IsItemForCommandIdDynamic(int command_id) |
| 150 const { | 148 const { |
| 151 return command_id == kTogglePermissionCommand || | 149 return command_id == kTogglePermissionCommand || |
| 152 command_id == kToggleExtensionCommand; | 150 command_id == kToggleExtensionCommand; |
| 153 } | 151 } |
| 154 | 152 |
| 155 string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id) | 153 string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id) |
| 156 const { | 154 const { |
| 157 // TODO(tfarina,johnnyg): Removed this code if we decide to close | 155 // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications |
| 158 // notifications after permissions are revoked. | 156 // after permissions are revoked. |
| 159 if (command_id == kTogglePermissionCommand || | 157 if (command_id == kTogglePermissionCommand || |
| 160 command_id == kToggleExtensionCommand) { | 158 command_id == kToggleExtensionCommand) { |
| 161 const Notification& notification = balloon_->notification(); | 159 const Notification& notification = balloon_->notification(); |
| 162 const GURL& origin = notification.origin_url(); | 160 const GURL& origin = notification.origin_url(); |
| 163 | 161 |
| 164 DesktopNotificationService* service = | 162 DesktopNotificationService* service = |
| 165 balloon_->profile()->GetDesktopNotificationService(); | 163 balloon_->profile()->GetDesktopNotificationService(); |
| 166 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 164 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
| 167 ExtensionService* ext_service = | 165 ExtensionService* ext_service = |
| 168 balloon_->profile()->GetExtensionService(); | 166 balloon_->profile()->GetExtensionService(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 ExtensionPrefs* extension_prefs = ext_service->extension_prefs(); | 227 ExtensionPrefs* extension_prefs = ext_service->extension_prefs(); |
| 230 const std::string& id = extension->id(); | 228 const std::string& id = extension->id(); |
| 231 if (extension_prefs->GetExtensionState(id) == Extension::ENABLED) | 229 if (extension_prefs->GetExtensionState(id) == Extension::ENABLED) |
| 232 ext_service->DisableExtension(id); | 230 ext_service->DisableExtension(id); |
| 233 else | 231 else |
| 234 ext_service->EnableExtension(id); | 232 ext_service->EnableExtension(id); |
| 235 } | 233 } |
| 236 break; | 234 break; |
| 237 } | 235 } |
| 238 case kOpenContentSettingsCommand: { | 236 case kOpenContentSettingsCommand: { |
| 239 Browser* browser = BrowserList::GetLastActive(); | 237 TabContents* tab_contents = |
| 240 if (browser) { | 238 balloon_->view()->GetHost()->associated_tab_contents(); |
| 241 static_cast<TabContentsDelegate*>(browser)->ShowContentSettingsWindow( | 239 tab_contents->delegate()->ShowContentSettingsPage( |
| 242 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 240 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 243 } else { | |
| 244 #if defined(OS_WIN) | |
| 245 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 246 switches::kChromeFrame)) { | |
| 247 // We may not have a browser if this is a chrome frame process. | |
| 248 browser::ShowContentSettingsWindow(NULL, | |
| 249 CONTENT_SETTINGS_TYPE_DEFAULT, | |
| 250 balloon_->profile()); | |
| 251 } | |
| 252 #endif // OS_WIN | |
| 253 } | |
| 254 break; | 241 break; |
| 255 } | 242 } |
| 256 default: | 243 default: |
| 257 NOTREACHED(); | 244 NOTREACHED(); |
| 258 break; | 245 break; |
| 259 } | 246 } |
| 260 } | 247 } |
| OLD | NEW |