| 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 #include "chrome/browser/notifications/notification_options_menu_model.h" | 5 #include "chrome/browser/notifications/notification_options_menu_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon) | 133 NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon) |
| 134 : ui::SimpleMenuModel(this), | 134 : ui::SimpleMenuModel(this), |
| 135 balloon_(balloon) { | 135 balloon_(balloon) { |
| 136 const Notification& notification = balloon->notification(); | 136 const Notification& notification = balloon->notification(); |
| 137 const GURL& origin = notification.origin_url(); | 137 const GURL& origin = notification.origin_url(); |
| 138 | 138 |
| 139 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 139 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 140 ExtensionService* extension_service = | 140 ExtensionService* extension_service = |
| 141 balloon_->profile()->GetExtensionService(); | 141 balloon_->profile()->GetExtensionService(); |
| 142 const extensions::Extension* extension = | 142 const extensions::Extension* extension = |
| 143 extension_service->extensions()->GetExtensionOrAppByURL( | 143 extension_service->extensions()->GetExtensionOrAppByURL(origin); |
| 144 ExtensionURLInfo(origin)); | |
| 145 // We get back no extension here when we show the notification after | 144 // We get back no extension here when we show the notification after |
| 146 // the extension has crashed. | 145 // the extension has crashed. |
| 147 if (extension) { | 146 if (extension) { |
| 148 const string16 disable_label = l10n_util::GetStringUTF16( | 147 const string16 disable_label = l10n_util::GetStringUTF16( |
| 149 IDS_EXTENSIONS_DISABLE); | 148 IDS_EXTENSIONS_DISABLE); |
| 150 AddItem(kToggleExtensionCommand, disable_label); | 149 AddItem(kToggleExtensionCommand, disable_label); |
| 151 } | 150 } |
| 152 } else if (!notification.display_source().empty()) { | 151 } else if (!notification.display_source().empty()) { |
| 153 const string16 disable_label = l10n_util::GetStringFUTF16( | 152 const string16 disable_label = l10n_util::GetStringFUTF16( |
| 154 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, | 153 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 185 command_id == kToggleExtensionCommand) { | 184 command_id == kToggleExtensionCommand) { |
| 186 const Notification& notification = balloon_->notification(); | 185 const Notification& notification = balloon_->notification(); |
| 187 const GURL& origin = notification.origin_url(); | 186 const GURL& origin = notification.origin_url(); |
| 188 | 187 |
| 189 DesktopNotificationService* service = | 188 DesktopNotificationService* service = |
| 190 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); | 189 DesktopNotificationServiceFactory::GetForProfile(balloon_->profile()); |
| 191 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 190 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 192 ExtensionService* extension_service = | 191 ExtensionService* extension_service = |
| 193 balloon_->profile()->GetExtensionService(); | 192 balloon_->profile()->GetExtensionService(); |
| 194 const extensions::Extension* extension = | 193 const extensions::Extension* extension = |
| 195 extension_service->extensions()->GetExtensionOrAppByURL( | 194 extension_service->extensions()->GetExtensionOrAppByURL(origin); |
| 196 ExtensionURLInfo(origin)); | |
| 197 if (extension) { | 195 if (extension) { |
| 198 return l10n_util::GetStringUTF16( | 196 return l10n_util::GetStringUTF16( |
| 199 extension_service->IsExtensionEnabled(extension->id()) ? | 197 extension_service->IsExtensionEnabled(extension->id()) ? |
| 200 IDS_EXTENSIONS_DISABLE : | 198 IDS_EXTENSIONS_DISABLE : |
| 201 IDS_EXTENSIONS_ENABLE); | 199 IDS_EXTENSIONS_ENABLE); |
| 202 } | 200 } |
| 203 } else { | 201 } else { |
| 204 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) { | 202 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) { |
| 205 return l10n_util::GetStringFUTF16( | 203 return l10n_util::GetStringFUTF16( |
| 206 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, | 204 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 const GURL& origin = balloon_->notification().origin_url(); | 242 const GURL& origin = balloon_->notification().origin_url(); |
| 245 switch (command_id) { | 243 switch (command_id) { |
| 246 case kTogglePermissionCommand: | 244 case kTogglePermissionCommand: |
| 247 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) | 245 if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) |
| 248 service->DenyPermission(origin); | 246 service->DenyPermission(origin); |
| 249 else | 247 else |
| 250 service->GrantPermission(origin); | 248 service->GrantPermission(origin); |
| 251 break; | 249 break; |
| 252 case kToggleExtensionCommand: { | 250 case kToggleExtensionCommand: { |
| 253 const extensions::Extension* extension = | 251 const extensions::Extension* extension = |
| 254 extension_service->extensions()->GetExtensionOrAppByURL( | 252 extension_service->extensions()->GetExtensionOrAppByURL(origin); |
| 255 ExtensionURLInfo(origin)); | |
| 256 if (extension) { | 253 if (extension) { |
| 257 const std::string& id = extension->id(); | 254 const std::string& id = extension->id(); |
| 258 if (extension_service->IsExtensionEnabled(id)) | 255 if (extension_service->IsExtensionEnabled(id)) |
| 259 extension_service->DisableExtension( | 256 extension_service->DisableExtension( |
| 260 id, extensions::Extension::DISABLE_USER_ACTION); | 257 id, extensions::Extension::DISABLE_USER_ACTION); |
| 261 else | 258 else |
| 262 extension_service->EnableExtension(id); | 259 extension_service->EnableExtension(id); |
| 263 } | 260 } |
| 264 break; | 261 break; |
| 265 } | 262 } |
| 266 case kOpenContentSettingsCommand: { | 263 case kOpenContentSettingsCommand: { |
| 267 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); | 264 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); |
| 268 Browser* browser = chrome::FindLastActiveWithProfile( | 265 Browser* browser = chrome::FindLastActiveWithProfile( |
| 269 balloon_->profile(), active_desktop); | 266 balloon_->profile(), active_desktop); |
| 270 if (!browser) { | 267 if (!browser) { |
| 271 // It is possible that there is no browser window (e.g. when there are | 268 // It is possible that there is no browser window (e.g. when there are |
| 272 // background pages, or for a chrome frame process on windows). | 269 // background pages, or for a chrome frame process on windows). |
| 273 browser = new Browser(Browser::CreateParams(balloon_->profile(), | 270 browser = new Browser(Browser::CreateParams(balloon_->profile(), |
| 274 active_desktop)); | 271 active_desktop)); |
| 275 } | 272 } |
| 276 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 273 chrome::ShowContentSettings(browser, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 277 break; | 274 break; |
| 278 } | 275 } |
| 279 default: | 276 default: |
| 280 NOTREACHED(); | 277 NOTREACHED(); |
| 281 break; | 278 break; |
| 282 } | 279 } |
| 283 } | 280 } |
| OLD | NEW |