| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/notifications/balloon_collection.h" | 12 #include "chrome/browser/notifications/balloon_collection.h" |
| 13 #include "chrome/browser/notifications/balloon_host.h" | 13 #include "chrome/browser/notifications/balloon_host.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_service.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service_factory.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/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/content_settings_types.h" | 22 #include "chrome/common/content_settings_types.h" |
| 22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/tab_contents/tab_contents.h" | 25 #include "content/browser/tab_contents/tab_contents.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id) | 154 string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id) |
| 154 const { | 155 const { |
| 155 // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications | 156 // TODO(tfarina,johnnyg): Remove this code if we decide to close notifications |
| 156 // after permissions are revoked. | 157 // after permissions are revoked. |
| 157 if (command_id == kTogglePermissionCommand || | 158 if (command_id == kTogglePermissionCommand || |
| 158 command_id == kToggleExtensionCommand) { | 159 command_id == kToggleExtensionCommand) { |
| 159 const Notification& notification = balloon_->notification(); | 160 const Notification& notification = balloon_->notification(); |
| 160 const GURL& origin = notification.origin_url(); | 161 const GURL& origin = notification.origin_url(); |
| 161 | 162 |
| 162 DesktopNotificationService* service = | 163 DesktopNotificationService* service = |
| 163 balloon_->profile()->GetDesktopNotificationService(); | 164 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); |
| 164 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 165 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
| 165 ExtensionService* ext_service = | 166 ExtensionService* ext_service = |
| 166 balloon_->profile()->GetExtensionService(); | 167 balloon_->profile()->GetExtensionService(); |
| 167 const Extension* extension = ext_service->GetExtensionByURL(origin); | 168 const Extension* extension = ext_service->GetExtensionByURL(origin); |
| 168 if (extension) { | 169 if (extension) { |
| 169 ExtensionPrefs* extension_prefs = ext_service->extension_prefs(); | 170 ExtensionPrefs* extension_prefs = ext_service->extension_prefs(); |
| 170 const std::string& id = extension->id(); | 171 const std::string& id = extension->id(); |
| 171 if (extension_prefs->GetExtensionState(id) == Extension::ENABLED) | 172 if (extension_prefs->GetExtensionState(id) == Extension::ENABLED) |
| 172 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE); | 173 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE); |
| 173 else | 174 else |
| (...skipping 29 matching lines...) Expand all Loading... |
| 203 } | 204 } |
| 204 | 205 |
| 205 bool NotificationOptionsMenuModel::GetAcceleratorForCommandId( | 206 bool NotificationOptionsMenuModel::GetAcceleratorForCommandId( |
| 206 int /* command_id */, ui::Accelerator* /* accelerator */) { | 207 int /* command_id */, ui::Accelerator* /* accelerator */) { |
| 207 // Currently no accelerators. | 208 // Currently no accelerators. |
| 208 return false; | 209 return false; |
| 209 } | 210 } |
| 210 | 211 |
| 211 void NotificationOptionsMenuModel::ExecuteCommand(int command_id) { | 212 void NotificationOptionsMenuModel::ExecuteCommand(int command_id) { |
| 212 DesktopNotificationService* service = | 213 DesktopNotificationService* service = |
| 213 balloon_->profile()->GetDesktopNotificationService(); | 214 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); |
| 214 ExtensionService* ext_service = | 215 ExtensionService* ext_service = |
| 215 balloon_->profile()->GetExtensionService(); | 216 balloon_->profile()->GetExtensionService(); |
| 216 const GURL& origin = balloon_->notification().origin_url(); | 217 const GURL& origin = balloon_->notification().origin_url(); |
| 217 switch (command_id) { | 218 switch (command_id) { |
| 218 case kTogglePermissionCommand: | 219 case kTogglePermissionCommand: |
| 219 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) | 220 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) |
| 220 service->DenyPermission(origin); | 221 service->DenyPermission(origin); |
| 221 else | 222 else |
| 222 service->GrantPermission(origin); | 223 service->GrantPermission(origin); |
| 223 break; | 224 break; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 238 balloon_->view()->GetHost()->associated_tab_contents(); | 239 balloon_->view()->GetHost()->associated_tab_contents(); |
| 239 tab_contents->delegate()->ShowContentSettingsPage( | 240 tab_contents->delegate()->ShowContentSettingsPage( |
| 240 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 241 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 241 break; | 242 break; |
| 242 } | 243 } |
| 243 default: | 244 default: |
| 244 NOTREACHED(); | 245 NOTREACHED(); |
| 245 break; | 246 break; |
| 246 } | 247 } |
| 247 } | 248 } |
| OLD | NEW |