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